DATA Step, Macro, Functions and more

macro

Reply
N/A
Posts: 0

macro

%let qtr = 2009-12TestNS;

data _null_;
Call symput('qtrdata',%substr(&qtr,1,7));
run;

%put &qtr &qtrdata;

70 %put &qtr &qtrdata;
2009-12TestNS 1997


Do you know why it is doing &qtrdata = 1997??

I'm expecting &qtrdata = 2009-12
Super Contributor
Posts: 474

Re: macro

Yes.
[pre]
Call symput('qtrdata',%substr(&qtr,1,7));
[/pre]
will resolve to:
[pre]
Call symput('qtrdata',2009-12);
[/pre]
So 2009-12 = 1997.

SAS is doing an implicit numeric to char conversion and assigning '1997' to QTRDATA.

enclose your value into double quotes, like this
[pre]
Call symput('qtrdata',"%substr(&qtr,1,7)");
[/pre]
or

switch the macro function %substr to its datastep equivalent, and use double quotes arround QTR
[pre]
Call symput('qtrdata',substr("&qtr",1,7));
[/pre]
Cheers from Portugal

Daniel Santos @ www.cgd.pt
N/A
Posts: 0

Re: macro

Thank you!! It works.

how do i do it without call symput and just %let?

%let qtr = 2009-12TestNS;

%let qtrdata = ???
Valued Guide
Posts: 2,174

Re: macro

%Qsubstr( %superQ(qtr), 1,7 )
I've used the macro quoting functions to protect the minus sign from being treated as syntax
Valued Guide
Posts: 2,174

Re: macro

macro quoting is overkill here, as this saslog snippet indicates[pre]49 %let qtr = 2009-12TestNS;
50 %let qtrdata = %substr( &qtr, 1,7 ) ;
51 %put &qtrdata ;
2009-12
[/pre]
PeterC
N/A
Posts: 0

Re: macro

I tried doing this.

233 %let qtr = 2009-12TestNS;
234
235 %let qtrdata = %Qsubstr(%superQ(qtr), 1,7 )||PROD;
236
237 %put &qtr &qtrdata;
2009-12TestNS 2009-12||PROD


I'm expecting &qtrdata = 2009-12Prod
Valued Guide
Posts: 2,174

Re: macro

in the macro language of SAS, that concatenation symbol is unneccessary and is being treated as text[pre]
53 %let qtr = 2009-12TestNS;
54 %let qtrdata = %substr( &qtr, 1,7 )PROD;
55 %put &qtrdata ;
2009-12PROD[/pre]
N/A
Posts: 0

Re: macro

ah! thanks a lot!
Ask a Question
Discussion stats
  • 7 replies
  • 169 views
  • 0 likes
  • 3 in conversation