BookmarkSubscribeRSS Feed
data_null__
Jade | Level 19
I want to create a libref with a SAS generated named.  I can create a fileref with a SAS Generated name using a variable in the name field that is missing.  The function populates the name variable with a generated as #LN00013 see below.  It doesn't work that way for LIBREF in this program.  I know the libref is created I can see it with LIBNAME _ALL_ LIST; it is named WC000001.
18         data _null_;
19            length dd $8;
20            dd = ' ';;
21            rc = libname(dd,'~');
22            msg = sysmsg();
23            put _all_;
24            dd = ' ';
25            rc = filename(dd,'~');
26            msg = sysmsg();
27            put _all_;
28         run;

dd=  rc=
0 msg=  _ERROR_=0 _N_=1
dd=#LN00013 rc=
0 msg=  _ERROR_=0 _N_=1
8 REPLIES 8
PGStats
Opal | Level 21

I get something different when I run your code on 9.3 Win 7 , 32 bits :

dd=  rc=-70008 msg=NOTE: Library WC000001 does not exist. _ERROR_=0 _N_=1

dd=#LN00010 rc=0 msg=  _ERROR_=0 _N_=1

PG

PG
data_null__
Jade | Level 19

Did you use tilde ~? You need the proper path syntax for your OS.  I am UNIX and ~ means "home".

PGStats
Opal | Level 21

Yeah. If I use a period (current dir in Windows), I match your output :

dd=  rc=0 msg=  _ERROR_=0 _N_=1

dd=#LN00010 rc=0 msg=  _ERROR_=0 _N_=1

Looks like a case for Tech Support... But then, is name generation an official feature of SAS?

PG

PG
data_null__
Jade | Level 19

It seem like is must be a feature because SAS does generate the name and define the libref, note RC=0.  I just don't know how to get SAS to tell me what that name is.

But you may be right "we ain't s'pose to it that way".

ballardw
Super User

The automatic macro variable &SYSLAST will have the library and dataset name of the last created dataset. Parse the string for the library

 

%let lastlib = %scan(&syslast,1,'.');

%put &lastlib;

Tom
Super User Tom
Super User

The code is just making librefs, not creating any datasets, so SYSLAST macro variable will not be updated.

Tom
Super User Tom
Super User

Seems to be how it works.  Perhaps you can put it on the SAS ballot.

Meanwhile use FILENAME to generate the new name. You will need to modify it slightly to make it valid.

  data _null_;

     length fileref libref $8;

* Make FILEREF ;

     fileref = ' ';;

     rc = filename(fileref,'~');

     msg = sysmsg();

     put _all_;


* Generate LIBREF from FILEREF ;

     libref='_'||substr(fileref,2);


* clear FILENAME ;

     rc = filename(fileref,' ');

     msg = sysmsg();

     put _all_;

* Generate LIBNAME ;

     rc = libname(libref,'~');

     msg = sysmsg();

     put _all_;

  run;

fileref=#LN00023 libref=  rc=0 msg=  _ERROR_=0 _N_=1

fileref=  libref=_LN00023 rc=0 msg=  _ERROR_=0 _N_=1

fileref=  libref=_LN00023 rc=0 msg=  _ERROR_=0 _N_=1

data_null__
Jade | Level 19

I thought about that but ended up just using &SYSINDEX.

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
  • 8 replies
  • 1452 views
  • 0 likes
  • 4 in conversation