Dear All,
I ran into problem when I put path into macros. SAS has no problem to read in the data without macros.
Below are the SAS code and log. Thanks.
********************************************************************;
%let pat=C:\Users\zzz\Desktop\EEE\Dryrun2018\;
%let percent= &pat.Percentile_from_2017\;
FILENAME PT "&percent.NN2_2017_SS_FREQ" ; /*Percentile*/
data PT;
set PT ;
run;
938 %let pat=C:\Users\zzz\Desktop\EEE\Dryrun2018\;
939 %let percent= &pat.Percentile_from_2017\;
SYMBOLGEN: Macro variable PAT resolves to C:\Users\zzz\Desktop\EEE\Dryrun2018\
940 FILENAME PT "&percent.NN2_2017_SS_FREQ" ; /*Percentile*/
SYMBOLGEN: Macro variable PERCENT resolves to
C:\Users\zzz\Desktop\EEE\Dryrun2018\Percentile_from_2017\
941
942 data PT;
943 set PT ;
944 run;
NOTE: There were 0 observations read from the data set WORK.PT.
NOTE: The data set WORK.PT has 0 observations and 0 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
The FILENAME statement is intended to reference a non-SAS file.
SET is intended to read data from a SAS library.
When you say
set PT;
SAS is looking for a data set named PT in the default LIBRARY of work. Equivalent statement would be:
set Work.PT;
If the location represented by &percent is supposed to have SAS data sets (files with extensions like sas7bdat)
then you would use a LIBNAME statement to tell SAS you expect to find or place SAS data sets in that location.
Libname PT "&percent"; for example.
Then if there is data set named NN2_2017_SS_FREQ in that library use as:
data PT;
set PT.NN2_2017_SS_FREQ;
run;
Note the period between the library name and the data set name.
OR was FILENAME PT "&percent.NN2_2017_SS_FREQ" ; intended to reference a LIBRARY? Then use LIBNAME but you still need to use the LIBNAME.datasetname syntax.
BTW use of
Data Pt;
set Pt;
<other code>;
run;
Overwrites the existing Pt data set and may remove or alter data such that you no longer have what you expect.
Better, at least until you are much more familiar with SAS syntax to use:
data Pt2;
set Pt;
to avoid that.
The FILENAME statement is intended to reference a non-SAS file.
SET is intended to read data from a SAS library.
When you say
set PT;
SAS is looking for a data set named PT in the default LIBRARY of work. Equivalent statement would be:
set Work.PT;
If the location represented by &percent is supposed to have SAS data sets (files with extensions like sas7bdat)
then you would use a LIBNAME statement to tell SAS you expect to find or place SAS data sets in that location.
Libname PT "&percent"; for example.
Then if there is data set named NN2_2017_SS_FREQ in that library use as:
data PT;
set PT.NN2_2017_SS_FREQ;
run;
Note the period between the library name and the data set name.
OR was FILENAME PT "&percent.NN2_2017_SS_FREQ" ; intended to reference a LIBRARY? Then use LIBNAME but you still need to use the LIBNAME.datasetname syntax.
BTW use of
Data Pt;
set Pt;
<other code>;
run;
Overwrites the existing Pt data set and may remove or alter data such that you no longer have what you expect.
Better, at least until you are much more familiar with SAS syntax to use:
data Pt2;
set Pt;
to avoid that.
@TX_STAR wrote:
Dear All,
I ran into problem when I put path into macros. SAS has no problem to read in the data without macros.
Show us the code that works.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.