BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sk1_SAS
Obsidian | Level 7

Hi Team,

 

I need to create one base if the base name is >= 202004.. Is it possible? 

 

I tried this code, but it put all the bases together.

 

 

DATA MIS;
SET LIB._MIS:;
RUN;

 

 

 

name of the bases:

 

lib.MIS_201910
lib.MIS_201911
lib.MIS_201912
lib.MIS_202001
lib.MIS_202002
lib.MIS_202003
lib.MIS_202004
lib.MIS_202005
lib.MIS_202006
lib.MIS_202007
lib.MIS_202008
lib.MIS_202009
lib.MIS_202010
lib.MIS_202011
lib.MIS_202012
lib.MIS_202101
lib.MIS_202102
lib.MIS_202103

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Use double -- instead of single - check the link in the previous post for all the options.

Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

 

Or create a macro variable from sashelp.vtables.

 

proc sql noprint;
select memname into :Table_list separated by " "
from sashelp.vtable where libname = "LIB" and memname >= "MIS_202004";
quit;

%put &table_list;

View solution in original post

6 REPLIES 6
Reeza
Super User

Can you assume the last one will always be the current month?

If so you could do something like:

set lib.mis_202004 - lib.mis_%sysfunc(today(), yymmn6.);

EDIT: corrected to remove PUTN(), thanks to @SASKiwi 

Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

Sk1_SAS
Obsidian | Level 7

Yes, the last one is the current month.

 

I tried, and this error appears:

 

ERROR: Required operator not found in expression: today()
ERROR: Argument 1 to function PUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.
ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC
or %QSYSFUNC function reference is terminated.
ERROR: Missing numeric suffix on a numbered data set list (LIB.MIS_202004-LIB.MIS_).

SASKiwi
PROC Star

This works better: %sysfunc(today(), yymmn6.);

Sk1_SAS
Obsidian | Level 7

the data format did not work.

 

ERROR: File LIB.MIS_202013.DATA does not exist.
ERROR: File LIB.MIS_202014.DATA does not exist.
ERROR: File LIB.MIS_202015.DATA does not exist.
ERROR: File LIB.MIS_202016.DATA does not exist.
ERROR: File LIB.MIS_202017.DATA does not exist.
ERROR: File LIB.MIS_202018.DATA does not exist.
ERROR: File LIB.MIS_202019.DATA does not exist.
ERROR: File LIB.MIS_202020.DATA does not exist.
ERROR: File LIB.MIS_202021.DATA does not exist.
ERROR: File LIB.MIS_202022.DATA does not exist.

Reeza
Super User

Use double -- instead of single - check the link in the previous post for all the options.

Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

 

Or create a macro variable from sashelp.vtables.

 

proc sql noprint;
select memname into :Table_list separated by " "
from sashelp.vtable where libname = "LIB" and memname >= "MIS_202004";
quit;

%put &table_list;
Sk1_SAS
Obsidian | Level 7

DATA WANT; set lib.MIS_202004--LIB.MIS_%sysfunc(today(), yymmn6.); run;

22
76
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, _DATA_, _LAST_, _NULL_.

ERROR 76-322: Syntax error, statement will be ignored.

 

 

Not working 😞

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 569 views
  • 4 likes
  • 3 in conversation