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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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