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

Hi ,

 

I have a library called abcd and  in this library there are few data sets and one of the data set called Employers  is creating with dynamic number at the end of the data set every time like  Employers_1, employers_2 ,employers_12, employers_22 etc..

 

Solution i need: I Need a piece of code to read a latest data set which is creating with the dynamic number at the end.

 

Thanks in advance.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

Try

proc sql noprint;
   select MemName 
      into :LatestEmpDataset trimmed
      from sashelp.vtable
         where MemName like 'EMPLOYERS%'
            having modate = max(modate)
   ;
quit;

%put &=LatestEmpDataset.;

View solution in original post

7 REPLIES 7
andreas_lds
Jade | Level 19

Try

proc sql noprint;
   select MemName 
      into :LatestEmpDataset trimmed
      from sashelp.vtable
         where MemName like 'EMPLOYERS%'
            having modate = max(modate)
   ;
quit;

%put &=LatestEmpDataset.;
Pandu
Fluorite | Level 6

Thank you for your help..Its working for me as i expected.

Shmuel
Garnet | Level 18

You can scan sashelp.vmembers to select tables where LIBNAME=<your library> and scan(MEMNAME,1,'_')  = upcase('employers').

 

Then sort the list and select the required one.

 

For eample:

proc sort data=sashelp.vmembers(where=(
                   libname = "MY_LIB" and 
                   scan(memname,1,'_') = 'EMLOYERS'))
             out=emp_list(keep=memname);
        by libname memname;
run;

data _null_;
 set emp_list;
    by memname;
        if last.memname then
           call symput(last_emp,trim(memname));
run;
%put Last dataset is &lat_emp; 
        

finally see the log. 

Addapt it to your needs. 

 

 

Pandu
Fluorite | Level 6

But i don't have any vmembers exist in abcd library like Sashelp.

 

under  abcd  library i have these are the nly tables i have.

Employers_1

Employers_2

Employers_3

Employers_4

 

Shmuel
Garnet | Level 18

@Pandu wrote:

But i don't have any vmembers exist in abcd library like Sashelp.

 

under  abcd  library i have these are the nly tables i have.

Employers_1

Employers_2

Employers_3

Employers_4

 


look for library named sashelp, there you will find the table vmembers.

Pandu
Fluorite | Level 6

Thank you for your help..Its working for me as i expected.

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Question 1, why do you have multiple datasets containing the same data?  This is not good data modelling, keep all like data in one dataset, you can add a variable for the increment.  This minimises storage, I/O, and programming time.  For instance if you had:

Employers:

Iteration   ...

1              ...

...

2              ...

 

You question would simply be a matter of where clausing the data out.  

 

Putting "data" in table names or column names will increase your program code and make for spaghetti code.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 851 views
  • 3 likes
  • 4 in conversation