DATA Step, Macro, Functions and more

Employers_1, employers_2 etc...

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Employers_1, employers_2 etc...

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.

 

 

 

 


Accepted Solutions
Solution
‎04-11-2018 07:43 AM
Valued Guide
Posts: 630

Re: Employers_1, employers_2 etc...

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


All Replies
Solution
‎04-11-2018 07:43 AM
Valued Guide
Posts: 630

Re: Employers_1, employers_2 etc...

Try

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

%put &=LatestEmpDataset.;
Occasional Contributor
Posts: 9

Re: Employers_1, employers_2 etc...

Posted in reply to andreas_lds

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

Trusted Advisor
Posts: 1,848

Re: Employers_1, employers_2 etc...

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. 

 

 

Occasional Contributor
Posts: 9

Re: Employers_1, employers_2 etc...

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

 

Trusted Advisor
Posts: 1,848

Re: Employers_1, employers_2 etc...


@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.

Occasional Contributor
Posts: 9

Re: Employers_1, employers_2 etc...

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

 

 

Super User
Super User
Posts: 9,840

Re: Employers_1, employers_2 etc...

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 142 views
  • 3 likes
  • 4 in conversation