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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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