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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 873 views
  • 0 likes
  • 2 in conversation