I just want to assign a file path to FILENAME in the below code but I know I am doing some simple mistake to get the result.
Actual issue: Text2 variable value(Contains file path with name) need to assigned to macro variable, so that I can assign macro variable for FILENAME function for file path. But macro variable is not working in Filename function.
data testData; set ds2; text=cats(put(date,yymmn6.),put("W",1.),put(week,1.)); text1=cats(put("Final_file_",12.),put(text,10.),put(".txt",5.)); text2 = cats(put("""",1.),put("/path/Data_process/",50.),put("/",1.),put(text1,25.),put("""",1.)); call symputx('nm_fl',put(text2,50.),'G'); run; -------------------------------------------------------------- %put &nm_fl; filename myfile &nm_fl1.; ----------------------------------------------------------------- data "/pathsample_pipe_delimited_dataset"; infile myfile dlm='|' dsd FIRSTOBS=2; input FIELD1 $ FIELD2; format FIELD2; 30.; run;
There is absolutely no need to include put and a format in your CAT function calls when a variable is not involved. Make sure that the formats match the variable type or unexpected results may occur.
You should show the log and the likely errors generated:
text1=cats(put("Final_file_",12.),put(text,10.),put(".txt",5.));
Since "final_file_" is literal text Put using a 12. format is wrong as 12. is for numeric
text=cats(put(date,yymmn6.),"W",put(week,1.));
text1=cats("Final_file_",text,".txt");
text2 = cats('"/path/Data_process/',text1,'"');
call symputx('nm_fl',text2,'G');
may be a bit closer to what you want. And did you really want 2 / next to each other in text2?
Generally I avoid actually placing quotes inside of macro variables as it seems the results are more fragile.
Did you try %Put &nm_fl to see what the variable resolved to?
Also, is there more than one record in your dataset DS2? If so, you are only going to get one macro variable for the last record as a result.
Also note that
data "/pathsample_pipe_delimited_dataset";
is possibly going to have an issue with the length of the name besides the poor idea of the "name literal"
There is absolutely no need to include put and a format in your CAT function calls when a variable is not involved. Make sure that the formats match the variable type or unexpected results may occur.
You should show the log and the likely errors generated:
text1=cats(put("Final_file_",12.),put(text,10.),put(".txt",5.));
Since "final_file_" is literal text Put using a 12. format is wrong as 12. is for numeric
text=cats(put(date,yymmn6.),"W",put(week,1.));
text1=cats("Final_file_",text,".txt");
text2 = cats('"/path/Data_process/',text1,'"');
call symputx('nm_fl',text2,'G');
may be a bit closer to what you want. And did you really want 2 / next to each other in text2?
Generally I avoid actually placing quotes inside of macro variables as it seems the results are more fragile.
Did you try %Put &nm_fl to see what the variable resolved to?
Also, is there more than one record in your dataset DS2? If so, you are only going to get one macro variable for the last record as a result.
Also note that
data "/pathsample_pipe_delimited_dataset";
is possibly going to have an issue with the length of the name besides the poor idea of the "name literal"
Thanks a lot for your solution. It works great now.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: