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?
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;
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.
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.