BookmarkSubscribeRSS Feed
jerry898969
Pyrite | Level 9

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

5 REPLIES 5
NickR
Quartz | Level 8

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;

data_null__
Jade | Level 19

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;

Ksharp
Super User

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

Howles
Quartz | Level 8

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

Ksharp
Super User

H. Howles

Maybe it should be vvaluex()?

Ksharp

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 8589 views
  • 0 likes
  • 5 in conversation