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 Experts,

 

My data is : 

MarieT_0-1615888014937.png

I would like to extract the name from first row and put it as coulumn name. I would like to do that with proc contents and after do the set of two tables. Maybe you know the easiest method ? 

 

Thank you for your help !

1 ACCEPTED SOLUTION
4 REPLIES 4
Ksharp
Super User
Better post some REAL data , not just a picture .
Sajid01
Meteorite | Level 14

If the first row has names, one should be able to do that in the import processes in most scenarios
Please share how you are importing and atleast the first few rows..

Tom
Super User Tom
Super User

PROC TRANSPOSE is the way to do this.

Let's say your existing dataset is named HAVE.

proc transpose data=have(obs=1) out=names ;
  var _all_;
run;

This will produce a dataset with two variables _NAME_ with the orignal names and COL1 with the values from the first row.

 

The values in your photograph look more like labels than names so let's use this information to generate a LABEL statement instead of a RENAME statement.

filename code temp;
data _null_;
   set names end=eof;
   file code ;
   if _n_=1 then put 'label' ;
  put @3 _name_ '=' col1 :$quote. ;
  if eof then put ';' ;
run;

data want;
  set have(firstobs=2);
  %include code / source2;
run;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 564 views
  • 4 likes
  • 5 in conversation