BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11
Hello,

I would like to keep the first column from table SAS. I know the Label name but I don’t know the name of this varaiable. Proc content can’t help. Do you have some ideas?
Thank you very much!

Best regards,
Marie
1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Alternatively by proc contents as well you will know the column position and variable name as below

 

proc contents data=sashelp.class;
run;

image.png

Thanks,
Jag

View solution in original post

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

Lets try to identify the columns name based on the column position, in your example we need to identify the first column so we need to use dictionary.columns as below so based on where varnum variable you will know the column orders and the first column will have varnum=1 and from the name column you will know the variable name to use further. Try this on you dataset

 

proc sql;
create table want as select * from dictionary.columns where libname='SASHELP' and memname='CLASS';
run;

image.png

Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

Alternatively by proc contents as well you will know the column position and variable name as below

 

proc contents data=sashelp.class;
run;

image.png

Thanks,
Jag
Ksharp
Super User

Why would you say " Proc content can’t help" .

Once running the following code you could get the first variable name .

data have;
 set sashelp.class;
 label name='xxxxxx' age='yyyyyy';
run;

proc contents data=have varnum;
run;
                                      Variables in Creation Order

                                #    Variable    Type    Len    Label

                                1    Name        Char      8    xxxxxx
                                2    Sex         Char      1
                                3    Age         Num       8    yyyyyy
                                4    Height      Num       8
                                5    Weight      Num       8

 

Or Try following code .

data _null_;
 set have;
 array n{*} _numeric_;
 array c{*} _character_;
 do i=1 to dim(n);
   if vlabel(n{i})='xxxxxx' then call symputx('first_name',vname(n{i}));
 end;
 do i=1 to dim(c);
   if vlabel(c{i})='xxxxxx' then call symputx('first_name',vname(c{i}));
 end;
run;

data want;
 set have;
 drop &first_name;
run;
RichardDeVen
Barite | Level 11

The VNEXT call routine will iterate through the PDV variable names.  The first call will return the first variable name.

Use the returned variable name in a DOSUBL function call that runs a 'slicing' step.

 

Example:

data _null_;
  if 0 then set sashelp.cars;
  length _name_ $32;
  call vnext(_name_);

  rc = dosubl("data want; set sashelp.cars (keep=" || trim(_name_) || ");");

  stop;
run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 792 views
  • 1 like
  • 4 in conversation