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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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