Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format dates from macro value

Status
Not open for further replies.

Queryman

Programmer
Nov 4, 2002
243
US
I have a macro(SVCDATE1) that has the following value
'2002-11-01'
I need to make another macro using this value and the new macro(RSVCDATE1)needs to be in this format
'200211'
Any suggestions?
Thanks!

QueryMan

 
Hi Queryman,

when I remember your previous requests correctly, you have the single quotes actually on that variable's content. Don't have a manual around here, so don't know if there is a format to map this in a one liner - therefore less clever:

Code:
%let SVCDATE1='2002-11-01';

data _null_;
   y = substr ("&SVCDATE1.", 2, 4);
   m = substr ("&SVCDATE1.", 7, 2);
   call symput ("RSVCDATE1", trim(y) || m);
run;

%put &RSVCDATE1.;

Please note that this will work in SAS 8 and above - macro variable names get too long otherwise (>8 chars).

Cheers,
Matthias
 
Thanks again Matthias, how do I get RSVCDATE1 to display '112002' instead of 112002?

QueryMan

 
Okay the following worked, unless you have a more elegant solution.

data _null_;
q = substr ("&SVCDATE1.", 1, 1);
y = substr ("&SVCDATE1.", 2, 4);
m = substr ("&SVCDATE1.", 7, 2);
call symput ("RSVCDATE1",trim(q)||trim(y)||trim(m)||trim(q));
run;
%put &RSVCDATE1.;


QueryMan

 
Hi Queryman,

first char on your input is always single quote, so you do not necessarily have to read it into a var (unless this could change) - so:

Code:
call symput ("RSVCDATE1","'"||trim(y)||trim(m)||"'");

Cheers,
Matthias
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top