BookmarkSubscribeRSS Feed
pawandh
Fluorite | Level 6

I want to create a data set with following macro variable.

 

%let x =credit data;

 

data &x._&sysdate9.;

set t;

run;

Getting error, can not we remove the space within  a macro variable by using some function?

3 REPLIES 3
ChrisBrooks
Ammonite | Level 13

You can remove the space like this (note that you need to remove the dot before _&sysdate9

 

%let x =credit data;
 
data %sysfunc(compress(&x))_&sysdate9.;
set sashelp.class;
run;
Shmuel
Garnet | Level 18

DATA statement defines input dataset name in a format of <libref>.<DatasetName>.

LIBREF is defined by LIBNAME <libref> "path to data" and is limited to SAS names rules:

taken from http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214133.htm

 

libref

is a shortcut name or a "nickname" for the aggregate storage location where your SAS files are stored. It is any SAS name when you are assigning a new libref. When you are disassociating a libref from a SAS library or when you are listing attributes, specify a libref that was previously assigned.

Range: 1 to 8 characters
Tip: The association between a libref and a SAS library lasts only for the duration of the SAS session or until you change it or discontinue it with another LIBNAME statement.

 

 

therefore, as compressed &x is 'CreditData' - 10 characters long, it will end with error - illegal libref name.

 

Patrick
Opal | Level 21

@Shmuel

I believe you've missed that the dot after &x will be consumed by the macro processor and though &x becomes part of the table name which can be up to 32 characters.

@ChrisBrooks code looks like a suitable solution to me.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 8478 views
  • 0 likes
  • 4 in conversation