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-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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