10-03-2016 01:20 AM
10-03-2016 01:27 AM - edited 10-03-2016 01:27 AM
How do you know which data set is the latest? Is there some naming convention like a date in the name or a sequence number?
If so then you don't need to write a macro but you query the dictionary.tables and populate a macro variable for later use (see sample code below).
proc sql; select cats(libname,'.',memname) into :my_table_name from dictionary.tables where libname='COMMON' and memname ....<some condition(s) selecting the required table> ; quit; data want; set &my_table_name; run;
10-03-2016 04:00 AM
As mentioned by @Patrick, DICTIONARY.TABLES should contain the information you need. I suspect that you could use the CRDATE and MODATE columns. To get the latest, use the max() function with a HAVING statement.
10-03-2016 04:20 AM
10-03-2016 02:03 AM - edited 10-03-2016 02:06 AM
How is this different than your previous question which had several worked examples?
If you absolutely want a macro because it's your homework wrap the code between %macro and %mend.
*code already provided;
If you want some sort of dynamic nature to this you need to be more explicit in your requirements. You could add parameters for library name and what you wanted the macro variable to be called. But you haven't explained what you want.
Here's a link on into to macro programming to help you change the code if required.
10-03-2016 05:09 AM
Just I wanted to extract latest dataset in a library called common. I tried to use proc sql but it's display all the datasets, I need single dataset which id created recently and later I need to write macro for the same.
Any idea how to do it?
See this example:
16 proc sql noprint; 17 select name into :names from sashelp.class order by name descending; 18 quit; NOTE: PROCEDURE SQL used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 19 %put "names=&names"; "names=William "
Note that the macro variable contains only one entry, coming from the first line that the order by clause delivers.
proc sql noprint; select memname into :memname from dictionary.tables where libname = 'COMMON' order by memname descending; quit;
should deliver the last dataset from library COMMON in macro variable &memname.