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.
Try
proc sql noprint;
select MemName
into :LatestEmpDataset trimmed
from sashelp.vtable
where MemName like 'EMPLOYERS%'
having modate = max(modate)
;
quit;
%put &=LatestEmpDataset.;
Try
proc sql noprint;
select MemName
into :LatestEmpDataset trimmed
from sashelp.vtable
where MemName like 'EMPLOYERS%'
having modate = max(modate)
;
quit;
%put &=LatestEmpDataset.;
Thank you for your help..Its working for me as i expected.
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.
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
@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.
Thank you for your help..Its working for me as i expected.
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.
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.
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.