Hello Experts,
My data is :
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 !
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..
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;
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!
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.