Good Morning,
I am currently trying to assign a filepath to a variable and use variables in it as the file will be named for the months data.
E.G - /filepath/merhcant_july_2015.csv
When I declare the variable I get
SUMBOLGEN: Macro variabel MTN resolves to July.
However, when I attempt to use it in my call symput for the filepath it simply comes up as a .
I also declare the year and that variable is working fine.
Code:
data _null_;
rptdt = today();
today=today();
eow = intnx('week.2',today,-1,'End');
call symput('sun', put(eow,yymmdd10.));
call symput('mnth',put(eow,monname5.));
call symput('yr',put(eow,year.));
run;
data _null_;
call symput('filepath',"'/filepath/merchant_"||trim(left(&mnth||"_"||trim(left(&yr))||".csv'");
run;
%put &mnth &sun &yr &filepath;
Because the variable JULY is missing in your second data step. If you intended the LEFT() functions arguments to include the literal value July then you need in put it in quotes. Otherwise it looks like a variable reference.
%put call symput('filepath',"'/filepath/merchant_"||trim(left(&mnth||"_"||trim(left(&yr))||".csv'");
call symput('filepath',"'/filepath/merchant_"||trim(left(July||"_"||trim(left(2015))||".csv'")
Similarly for the macro variable YR, but in that case the value looks like a numeric literal.
Why not just set the value of FILEPATH directly ? Use CALL SYMPUTX() to prevent the extra spaces in the macro variables.
data _null_;
rptdt = today();
today=today();
eow = intnx('week.2',today,-1,'End');
call symputx('sun', put(eow,yymmdd10.));
call symputx('mnth',put(eow,monname5.));
call symputx('yr',put(eow,year.));
run;
%let filepath=%sysfunc(dequote("'/filepath/merchant_&mnth._&yr..csv'")) ;
%put filepath=&filepath;
filepath='/filepath/merchant_July_2015.csv'
Because the variable JULY is missing in your second data step. If you intended the LEFT() functions arguments to include the literal value July then you need in put it in quotes. Otherwise it looks like a variable reference.
%put call symput('filepath',"'/filepath/merchant_"||trim(left(&mnth||"_"||trim(left(&yr))||".csv'");
call symput('filepath',"'/filepath/merchant_"||trim(left(July||"_"||trim(left(2015))||".csv'")
Similarly for the macro variable YR, but in that case the value looks like a numeric literal.
Why not just set the value of FILEPATH directly ? Use CALL SYMPUTX() to prevent the extra spaces in the macro variables.
data _null_;
rptdt = today();
today=today();
eow = intnx('week.2',today,-1,'End');
call symputx('sun', put(eow,yymmdd10.));
call symputx('mnth',put(eow,monname5.));
call symputx('yr',put(eow,year.));
run;
%let filepath=%sysfunc(dequote("'/filepath/merchant_&mnth._&yr..csv'")) ;
%put filepath=&filepath;
filepath='/filepath/merchant_July_2015.csv'
Thank you Tom. This seems to have corrected the issue and simplified the code I was trying to use. I used SYMPUT as I am still new to SAS programming and had seen that used before. I am not sure how what you posted works, but I do know that it works. But I can do some research on SYMPUTX and %sysfunc to get an understanding of those commands.
Thank you again for the response.
CALL SYMPUTX() is new (less than 10 years old ). It makes the process of generating macro variables from data step easier in that it both trims the leading and trailing spaces and quietly converts numbers to text. Note that macro variables are always text strings since they are just a tool for building text.
The use of DEQUOTE() function allows you to easily generate the variable with single quotes around it as your original code was trying to do. Macro variables do not resolve inside of quoted strings that start with a single quote. If you are ok with making the macro variable use double quotes then you do not need that extra complexity.
%let filepath="/filepath/merchant_&mnth._&yr..csv" ;
Or your can leave off the quotes and add them back later when you reference the variable.
%let filepath=/filepath/merchant_&mnth._&yr..csv ;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.