DATA Step, Macro, Functions and more

Remove ".DATA" from a macro variable used in a set statement

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

Remove ".DATA" from a macro variable used in a set statement

[ Edited ]

Here is my code:

 

 

libname file0 'x/y/z';

 

data _null_;

yest = today() -1;

a = 'hamming_';

call symput('inventions',put("file0.",$6.)||put(a,$8.)||put(yest,yymmddn8.));

options symbolgen;

run;

 

data temp0;

set &inventions (obs=1);

run;

 

proc print data=temp0;

run;

 

symbolgen returns 'file0.hamming_20180417'

and i get an error in the set statement saying FILE 'file0.hamming_20180417.DATA' does not exist.

 

How can I remove this '.DATA'?

 

Thanks,

Jon

 


Accepted Solutions
Solution
‎04-19-2018 09:03 AM
Super User
Posts: 8,220

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

Is file0.hamming_20180417 a SAS dataset? If it isn't, you can't access it with a set statement.

 

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Super User
Posts: 8,220

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

You should get more errors than the one you showed as there were other errors in your code. And I think an extra space was imbedded in the file name. The following worked for me:

libname file0 '/folders/myfolders';

data _null_;
  yest = today() -1;
  a = 'hamming_';
  call symput('inventions',put("file0.",$6.)||put(a,$8.)||put(yest,yymmddn8.));
  options symbolgen;
run;

data &inventions.;
  set sashelp.class;
run;

data temp0;
  set &inventions (obs=1);
run;

proc print data=temp0;
run;

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 24

Re: Remove ".DATA" from a macro variable used in a set statement

thank you, yes in masking my actual program i made a couple errors, but i think i corrected them as you were responding...thank you!!

 

Anyway, can you please explain the structure:

 

data &inventions. ;

    set sashelp.class;

run;

 

whats going on there?  why do i need it?  I'm not questing if it should be there, i would just like to understand a bit on it.

 

Thanks,

Jon

Contributor
Posts: 24

Re: Remove ".DATA" from a macro variable used in a set statement

this is not working for me.  I still get the message from the set statement noting "xyz.DATA" does not exist, but the symbolgen produces the precise var that i want.

Super User
Posts: 8,220

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

Since your code was trying to open an existing file, I simply created that file using the datastep to create it with a copy of sashelp.class.

 

Unless you changed your symbolgen to match the one in my code, it was actually creating a macro variable that contained:

file0.hamming_ 20180417

A dataset name cannot include an imbedded blank.

 

My code, on the other hand, produced:

file0.hamming_20180417

Art, CEO, AnalystFinder.com

 

Contributor
Posts: 24

Re: Remove ".DATA" from a macro variable used in a set statement

yes, i corrected that error.  the code listed in my initial comment is fixed, and reflects my actual program.  thank you.  It still does not work.  is the variable being capitalized when referencing my file?  my file name is all lower case.

Contributor
Posts: 24

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

i notice in the log that everything is capitalized in the FILE 'FILE0....DATA' does not exist statement, but my actual file is all lower-case.  do i need to constrict it to lower-case?

Super User
Posts: 8,220

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

No. The log is simply showing it as uppercase, but it is actually lowercase.

 

Art, CEO, AnalystFinder.com

 

Solution
‎04-19-2018 09:03 AM
Super User
Posts: 8,220

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

Is file0.hamming_20180417 a SAS dataset? If it isn't, you can't access it with a set statement.

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 6,935

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

Based on the questions you are asking, you have been seriously misled.  This is not a good project for you.  It is unreasonable, dangerous, and should be postponed for 6 months until you have more experience using SAS language.

 

Macro language generates SAS programs.  You need more experience with SAS, to be able to visualize what a working SAS program looks like.  Even if your macro code runs without error, you won't know whether the program it generates is good or bad.  It is just too early in the game to be worrying about macro language.

Contributor
Posts: 24

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to Astounding

I must say, you're comment here struck a nerve with me.  At first, i was kind of upset - how could they?  But then I realized, maybe what this person is really trying to do is motivate me.  So, I took to proving you wrong so that I could get to where I need to be.  In that, I was proving that the var generated for the set statement was as it should be....and it is.  I checked with a prog that already has it, and the file location itself.  it all matched.  but i was sitll getting the error...then it donned on me to check the libname statement.  i did and discovered i left out the leading forward slash.  i put that in and everything is icecream.  you're right though, i should have known that the .DATA is a feature of the message, not what was actually being executed.  I won't forget that the next time around.  before i hang my head in shame, i just want to thank you, and anyone else who's attempted to help my mistake here.  i shall not forget this episode.  ok, now im hanging my head...................................and I'm done. moving on.   thanks again.

Super User
Posts: 10,592

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

Put your mind at rest, it's happened to all of us ...

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 6,935

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

You did well on all counts.  No head-hanging needed.

 

Your next step on the road (if you haven't done this already) is to omit a semicolon, then try to figure out why the statement that follows is invalid.

 

Best of luck.

Super User
Posts: 10,592

Re: Remove ".DATA" from a macro variable used in a set statement

Posted in reply to prolifious

The extension .DATA is always appended when a dataset name is included in the log. This can't be removed, as it is a given property of the SAS logger.

(if you were reading a view, the extension would be .VIEW, for example)

 

Your data _null_ code can be greatly simplified:

data _null_;
yest = today() -1;
call symput('inventions',"file0.hamming_"||put(yest,yymmddn8.));
run;

Note that no put() is needed for character variables, if you use them. But consider the use of strip() to remove leading and trailing blanks.

 

For the error, look if a file

hamming_20180418.sas7bdat

exists in directory

x/y/z

(or whatever is your real location).

SAS dataset filenames must be lowercase(!) in the file system, although SAS always spells them out in uppercase in the logs or in resources like dictionary.tables. That is a remnant of SAS's mainframe roots (where everything is uppercase), and the migration to UNIX (where filenames are mostly lowercase, and case-sensitive).

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 203 views
  • 6 likes
  • 4 in conversation