Discussion:
%sysfunc and date format
(too old to reply)
a***@mailinator.com
2007-09-05 15:57:01 UTC
Permalink
I need to convert a date value to 'yyyy/mm/dd' due to a proc sql where
clause that looks like

..and the_date >= ('2007/08/20')

to illustrate

data _null_;
a = '2007-08-20';
b = tranwrd(a,'-','/');
put a= b=;run;

a=2007-08-20 b=2007/08/20

tried this but it does not work

%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(tranwrd(&a,'-','/'));
%put &a &b;

ultimate I would want to do it directly in the proc sql statement,
something like

..and the_date >= (%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.)))
a***@mailinator.com
2007-09-05 16:13:42 UTC
Permalink
this works but not in the proc sql

%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(translate(%sysfunc(putn(%sysfunc(date()) -16,
yymmdd10.)),"/","-"));
%put &a &b;

2007-08-20 2007/08/20

..and date =
("%sysfunc(translate(%sysfunc(putn(%sysfunc(date()) -16,
yymmdd10.)),"/","-"))")

produces error in sas log

Column '2007/08/20' not found
s***@yahoo.com
2007-09-05 16:28:39 UTC
Permalink
Post by a***@mailinator.com
I need to convert a date value to 'yyyy/mm/dd' due to a proc sql where
clause that looks like
..and the_date >= ('2007/08/20')
to illustrate
data _null_;
a = '2007-08-20';
b = tranwrd(a,'-','/');
put a= b=;run;
a=2007-08-20 b=2007/08/20
tried this but it does not work
%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(tranwrd(&a,'-','/'));
%put &a &b;
ultimate I would want to do it directly in the proc sql statement,
something like
..and the_date >= (%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.)))
The format yymmddSw will do the trick.

1163 %put "(%sysfunc(putn(%sysfunc(date( )),YYMMDDs10.)))";
"(2007/09/05)"

HTH
a***@bigfoot.com
2007-09-05 16:50:36 UTC
Permalink
It's a pity that the data you're using PROC SQL on has dates stored as
character strings rather than numeric SAS dates.

Why not fix the data first, then you don't have the complication in
using it in PROC SQL?

data new_data_set;
set original_data_set;
sas_date = input(the_date, yymmdd10.);
run;

proc sql ...
and sas_date > '20AUG2007'd ...
Post by a***@mailinator.com
I need to convert a date value to 'yyyy/mm/dd' due to a proc sql where
clause that looks like
..and the_date >= ('2007/08/20')
to illustrate
data _null_;
a = '2007-08-20';
b = tranwrd(a,'-','/');
put a= b=;run;
a=2007-08-20 b=2007/08/20
tried this but it does not work
%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(tranwrd(&a,'-','/'));
%put &a &b;
ultimate I would want to do it directly in the proc sql statement,
something like
..and the_date >= (%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.)))
Terjeson, Mark
2007-09-05 16:16:01 UTC
Permalink
Hi,

The good news is you can do both.

data _null_;
a = '2007-08-20';
b = tranwrd(a,'-','/');
put a= b=;
run;

a=2007-08-20 b=2007/08/20


In the macro environment you can indeed use
datastep functions in the %SYSFUNC(), however
the only difference you need to be aware of
is that in the datastep environment you do
have to quote the strings as you have done.
In the macro environment ALL arguments and
variables are already treated as text so
typically the only difference when using
%SYSFUNC is to remove quotemarks around the
text strings. See as follows that your
tranwrd can work just fine in macro-land.


%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(tranwrd(&a,-,/));
%put a=&a b=&b;

a=2007-08-20 b=2007/08/20



As far as using a translation on-the-fly
in SQL is to just use the same function
syntax as you did in the datastep above.
e.g. tranwrd(a,'-','/')


Hint: everything you can put in an expression
to the right of the equals sign(=) in a
datastep you can put in the expression in
SQL to the left of the 'as' within the SELECT
clause. i.e.

datastep x = 7 * (4 + 6)
(is the same as)
SQL 7 * (4 + 6) as x


datastep x = 'abc'||tranwrd(a,'-','/')
(is the same as)
SQL 'abc'||tranwrd(a,'-','/') as x


Kinda makes ya think that you can imagine
the '=' and 'as' as the same..... just
swap sides (i.e. destination and expression)



Hope this is helpful.


Mark Terjeson
Senior Programmer Analyst, IM&R
Russell Investments


Russell Investments
Global Leaders in Multi-Manager Investing








-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-***@LISTSERV.UGA.EDU] On Behalf Of
***@MAILINATOR.COM
Sent: Wednesday, September 05, 2007 8:57 AM
To: SAS-***@LISTSERV.UGA.EDU
Subject: %sysfunc and date format

I need to convert a date value to 'yyyy/mm/dd' due to a proc sql where
clause that looks like

..and the_date >= ('2007/08/20')

to illustrate

data _null_;
a = '2007-08-20';
b = tranwrd(a,'-','/');
put a= b=;run;

a=2007-08-20 b=2007/08/20

tried this but it does not work

%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(tranwrd(&a,'-','/'));
%put &a &b;

ultimate I would want to do it directly in the proc sql statement,
something like

..and the_date >= (%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.)))
Chang Chung
2007-09-05 16:48:00 UTC
Permalink
Post by a***@mailinator.com
this works but not in the proc sql
%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(translate(%sysfunc(putn(%sysfunc(date()) -16,
yymmdd10.)),"/","-"));
%put &a &b;
2007-08-20 2007/08/20
..and date =
("%sysfunc(translate(%sysfunc(putn(%sysfunc(date()) -16,
yymmdd10.)),"/","-"))")
produces error in sas log
Column '2007/08/20' not found
hi,
with my 9.1.3 sp4 on my win xp, i get an error doing below, too. It seems
that proc sql has trouble with some macro quoted strings. Explicitly
unquoting works. HTH.
Cheers,
Chang

%let today = (%str(%')%sysfunc(date(), yymmdds10.)%str(%'));

/* bunch of errors */
proc sql;
select *
from sashelp.class
where '2007/01/01' < &today.;
quit;

/* this works fine */
proc sql;
select *
from sashelp.class
where '2007/01/01' < %unquote(&today.);
quit;
toby dunn
2007-09-05 16:18:52 UTC
Permalink
I dont recommend you store your dates like this as it is more trouble than
it is worth, Converting them to SAS date values allows you easier coding and
more possibilities when you have to deal with dates.

As for your code you need the following :

%Let A = 2007-08-20 ;
%Let B = %SysFunc( TranWrd( &A , - , / ) ) ;

%Put A=&A B=&B ;

Notice I didnt use quotes around the values in tranwrd, that is because in
the macro language everything is considered literal text, and only words
preceded by % and & are interpreted by SAS.



Toby Dunn

Comprimise is like telling a lie, it gets easier and easier. Each
comprimise you make, that becomes your standard.

Perfection doesnt exist, once you reach it, its not perfect anymore. It
means something else.





From: ***@MAILINATOR.COM
Reply-To: ***@MAILINATOR.COM
To: SAS-***@LISTSERV.UGA.EDU
Subject: %sysfunc and date format
Date: Wed, 5 Sep 2007 08:57:01 -0700

I need to convert a date value to 'yyyy/mm/dd' due to a proc sql where
clause that looks like

...and the_date >= ('2007/08/20')

to illustrate

data _null_;
a = '2007-08-20';
b = tranwrd(a,'-','/');
put a= b=;run;

a=2007-08-20 b=2007/08/20

tried this but it does not work

%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(tranwrd(&a,'-','/'));
%put &a &b;

ultimate I would want to do it directly in the proc sql statement,
something like

...and the_date >= (%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.)))

_________________________________________________________________
More photos; more messages; more whatever. Windows Live Hotmail - NOW with
5GB storage.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_5G_0907
David L Cassell
2007-09-06 03:33:06 UTC
Permalink
Post by a***@mailinator.com
I need to convert a date value to 'yyyy/mm/dd' due to a proc sql where
clause that looks like
..and the_date >= ('2007/08/20')
to illustrate
data _null_;
a = '2007-08-20';
b = tranwrd(a,'-','/');
put a= b=;run;
a=2007-08-20 b=2007/08/20
tried this but it does not work
%let a=%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.));
%let b=%sysfunc(tranwrd(&a,'-','/'));
%put &a &b;
ultimate I would want to do it directly in the proc sql statement,
something like
..and the_date >= (%sysfunc(putn(%sysfunc(date()) -16, yymmdd10.)))
Are you using PROC SQL and pass-through? It matters, because the
syntax for the data, and also the manner of quoting (single quotes, double
quotes, ...), are dependent on the application.

Let me guess. Oracle? If so, double quotes (as suggested elsewhere today)
will not work.

Are you really keeping your dates as text strings? That's a bad thing.
Don't do it in SAS, and don't do it in your RDBMS.

HTH,
David
--
David L. Cassell
mathematical statistician
Design Pathways
3115 NW Norwood Pl.
Corvallis OR 97330

_________________________________________________________________
Share your special parenting moments!
http://www.reallivemoms.com?ocid=TXT_TAGHM&loc=us

Loading...