DATA Step, Macro, Functions and more

Specifying file path in data step

Reply
Contributor
Posts: 23

Specifying file path in data step

Just gained ownership over some sas code that is not working at current:

 

data step has a merge statement that references a "master.sas7bdat" data set the following way:

 

merge msa$f..master(in = b);

 

where $f = module

 

However, the location of the file is ~msa/module/data and it returns with an error that there is no libname defined as msamodule.

 

Long story short-I am lost on how to properly specify the path, (and I don't know why the code suddenly broke when I gained ownership over this issue either).

Super User
Posts: 22,844

Re: Specifying file path in data step

Can you post the exact code, that doesn't look correct. 

Contributor
Posts: 23

Re: Specifying file path in data step

You are both right. The code uses a & not a $.

 

Exact Code:

 

data _null_;
   call symput("f","module");
run;

 

 

data cleanmaster2;
merge msa&f..master(in=b)

Super User
Posts: 13,023

Re: Specifying file path in data step

Are you sure the character $ in this code is what is actually in the code file?

 

merge msa$f..master(in = b);

 

I would more likely expect to see

 

merge msa&f..master(in = b);

 

which would expect the presence of a macro variable named F whose value is used to reference an existing library whose name starts with the letters MSA among a number of libraries. A further clue is the two periods in the statement as that is proper for used of a macro variable followed by an element that should contain a period such as the separator between a library name and the data set.

 

Suppose I had SAS libraries named:

msanew

msaold

msatest.

 

If I execute

%let f = new; assigning a value to a macro variable named f, then

msa&f  would resolve to msanew when used only as a library reference and

msa&f..master would resolve to msanew.master where a data set name was needed.

 

 

Contributor
Posts: 23

Re: Specifying file path in data step

Yes, as stated above for the other contributor: THe code is

 

data _null_;
   call symput("f","module");
run;

 

 

data cleanmaster2;
merge msa&f..master(in=b)

 

....etc

 

But I still don't know how to specify the path msa/module/data.master.sas (master is the name of the sas data set I need to pull in)

 

 

Super User
Posts: 22,844

Re: Specifying file path in data step

Look for something like the following:

 

libname msa&f 'path to folder here';

That sets the path to the msa folder and is what you need to change.

 

Super User
Posts: 13,023

Re: Specifying file path in data step


abak wrote:

 

data _null_;
   call symput("f","module");
run;

 

data cleanmaster2;
merge msa&f..master(in=b)

 

....etc

 

 


this code, and a Libname statement using msa&f will generate errors. Library names are limited to 8 characters.

msamodule would be 9 characters and hence invalid.

Ask a Question
Discussion stats
  • 6 replies
  • 151 views
  • 0 likes
  • 3 in conversation