Help using Base SAS procedures

Getting value from first column first row without knowing the variable name?

Reply
Super Contributor
Posts: 398

Getting value from first column first row without knowing the variable name?

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

Frequent Contributor
Posts: 81

Getting value from first column first row without knowing the variable name?

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;

Respected Advisor
Posts: 3,777

Re: Getting value from first column first row without knowing the variable name?

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;

Super User
Posts: 9,687

Re: Getting value from first column first row without knowing the variable name?

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

Regular Contributor
Posts: 184

Re: Getting value from first column first row without knowing the variable name?

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

Super User
Posts: 9,687

Re: Getting value from first column first row without knowing the variable name?

H. Howles

Maybe it should be vvaluex()?

Ksharp

Ask a Question
Discussion stats
  • 5 replies
  • 1972 views
  • 0 likes
  • 5 in conversation