Desktop productivity for business analysts and programmers

Resolved variable showing up as .

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Resolved variable showing up as .

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;


Accepted Solutions
Solution
‎07-22-2015 12:53 PM
Super User
Super User
Posts: 6,394

Re: Resolved variable showing up as .

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'

View solution in original post


All Replies
Solution
‎07-22-2015 12:53 PM
Super User
Super User
Posts: 6,394

Re: Resolved variable showing up as .

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'

Contributor
Posts: 21

Re: Resolved variable showing up as .

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.

Super User
Super User
Posts: 6,394

Re: Resolved variable showing up as .

CALL SYMPUTX() is new (less than 10 years old Smiley Happy ).  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 ;



☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 277 views
  • 1 like
  • 2 in conversation