Hello SAS Users! I am using a proc export step to export a txt file; however, the output keeps exporting without the ".txt" file extension.
PROC EXPORT DATA= survey
OUTFILE= "\\fakepath\survey_&today.txt"
DBMS= tab
REPLACE;
PUTNAMES=YES;
RUN ;
Output file looks like this: "survey_22May2020" without the ".txt" extension. So I have to open it in Notepad and save as a .txt as a manual workaround... Thoughts?
You need to have a '.' after the macro variable.
PROC EXPORT DATA= survey
OUTFILE= "\\fakepath\survey_&today..txt"
DBMS= tab
REPLACE;
PUTNAMES=YES;
RUN ;
You need to have a '.' after the macro variable.
PROC EXPORT DATA= survey
OUTFILE= "\\fakepath\survey_&today..txt"
DBMS= tab
REPLACE;
PUTNAMES=YES;
RUN ;
Oh wow! Such a silly mistake on my part. Thank you!
SAS uses a period to denote the end of a macro variable in code.
Example if you want to append an _ to the end of a macro variable you use something like:
%let base = abc; %let new = &base._; %put &new.
If you do not have the period the above example statement
%let new =&base_;
will generate an error because the macro variable Base is not terminated and you have told SAS to use a macro variable named base_.
So when you need to have a period as part of the resolved value after a macro variable you use two.
The same thing is needed when using any of The of the SAS syntax elements like Library.dataset. If both your library and data set names are stored in macro variables the proper reference would be &library..&dataset.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.