BookmarkSubscribeRSS Feed
SRINIVAS_N
Calcite | Level 5

Hi Everyone,

 

Can any one help me 

 

I have library name called 'op' in the library i have a datasets looks like

abc_201301

abc_201302

abc_201303

abc_201304

.

.

.

.

abc_201801

abc_201802

abc_201803

abc_201804

abc_201805

abc_201806

abc_201807

abc_201808

abc_201809

till the last month 

ex:if i ran a program the dataset today, it will create this year lastmonth(201809)

 

How can i show only last month dataset name

if the last month dataset is created show only last month dataset name ,if not created it should exit 

 

 

3 REPLIES 3
mkeintz
PROC Star

Please give a skeleton program.  I don't know what you mean by "exit".  Do you mean end the sas session?  Skip some other program steps?

 

 

Editted note.  Here's something close to what I think you want:

 

%let dsname=op.abc_%sysfunc(intnx(month,%sysfunc(today()),-1),yymmn6.);

%macro existds(name);
  %if %sysfunc(exist(&name)) %then 1;
  %else 0
%mend existds;
%put Dataset &dsname exist dummy is %existds(&dsname);

 

The main thing here is, given today's date, constructing the data set name corresponding to last month (op.abc_201809).  Above it's constructed in macro language.  In a data step, it would look something like:

 

data _null_;
  dsname=cats('op.abc_',put(intnx('month',today(),-1),yymmn6.));
  d=exist(dsname);
  put d=;
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SRINIVAS_N
Calcite | Level 5
If the current year previous month dataset is not present then it stop the
searching the dataset and come out of the loop
mkeintz
PROC Star

What loop?  Please show the code that implements the loop.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 699 views
  • 0 likes
  • 2 in conversation