BookmarkSubscribeRSS Feed
deleted_user
Not applicable
%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
7 REPLIES 7
DanielSantos
Barite | Level 11
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
deleted_user
Not applicable
Thank you!! It works.

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

%let qtr = 2009-12TestNS;

%let qtrdata = ???
Peter_C
Rhodochrosite | Level 12
%Qsubstr( %superQ(qtr), 1,7 )
I've used the macro quoting functions to protect the minus sign from being treated as syntax
Peter_C
Rhodochrosite | Level 12
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
deleted_user
Not applicable
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
Peter_C
Rhodochrosite | Level 12
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]
deleted_user
Not applicable
ah! thanks a lot!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1699 views
  • 0 likes
  • 3 in conversation