I need to get the value of the first variable first row of a data set without knowing the variable name.
The reason for this is I have to create a macro that will loop through many datasets and look at the first variable first row's value. Each data set has a different name for the first variable.
Any help would be appreciated.
Thank you
proc sql noprint;
select name into :firstvar from dictionary.columns where libname='SASHELP' and memname='CLASS'
and varnum=1;
quit;
proc print data=sashelp.class (obs=1);
var &firstvar;
run;
A slight variation on NickR's method. This gets a list of MEMNAMEs and variables NAMEs you can create a data table to run a macro or other code generator.
proc sql;
select name, memname
from dictionary.columns
where libname eq 'SASHELP' and memtype in('DATA') and varnum eq 1
;
quit;
run;
Hi. I found this can be achieve by proc sql. It is very interesting, but there a Warning message
in log , If you do not care about it.
proc sql noprint; select * into : first_value1 from sashelp.class; select * into : first_value2 from sashelp.air; quit; %put &first_value1 &first_value2; proc sql noprint; select * into : first_value1 from sashelp.class; select * into : first_value2 from sashelp.air; quit; %put &first_value1 &first_value2;
Ksharp
Here's a way using the DATA step:
data _null_ ;
set sashelp.shoes ;
length __name $32 ;
call vnext(__name);
r1c1 = vvalue(__name) ;
put r1c1= ;
stop ;
run ;
jerry898969 wrote:
I need to get the value of the first variable first row of a data set without knowing the variable name.
The reason for this is I have to create a macro that will loop through many datasets and look at the first variable first row's value. Each data set has a different name for the first variable.
Any help would be appreciated.
Thank you
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.