BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TX_STAR
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

Reeza
Super User

@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.

 

 

 

TX_STAR
Obsidian | Level 7

I did as 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1387 views
  • 3 likes
  • 3 in conversation