BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10
data have;
length
  a $25
  b $4
  c $8
  d $8
;
input a b c d ;
datalines;
dept month_ count_ status 
Acct JAN20 1 0 
Eng FEB20 1 1  
Sales FEB20 1 1   
 
;
run;
a b c d  
dept mont count_ status  
Acct JAN2 1 0  
Eng FEB2 1 1  
Sales FEB2 1 1  
         
Desire is replace row 1 and make them the header
dept mont count_ status  
Acct JAN2 1 0  
Eng FEB2 1 1  
Sales FEB2 1 1  

I tried

data have2 (firstobs=2);
set have;
;
run;

 

6 REPLIES 6
Tom
Super User Tom
Super User

Good start, although I would put the FIRSTOBS= dataset option on the INPUT dataset and not the OUTPUT dataset.

You also want to use the first row to RENAME the variables.  

Here is an easy method using PROC TRANSPOSE.

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

proc sql noprint;
  select catx('=',nliteral(_name_),nliteral(col1))
    into :renames separated by ' '
  from names
  where upcase(_name_) ne upcase(col1)
 ;
quit;

data want;
   set have (firstobs=2);
   rename &renames;
run;
Q1983
Lapis Lazuli | Level 10
When I run the last piece of code I get an error in the set data line. Should that be something else
55 data want;
56 set data (firstobs=2);
ERROR: File WORK.DATA.DATA does not exist.
SYMBOLGEN: Macro variable RENAMES resolves to a=dept
57 rename &renames;
58 run;

WARNING: The variable a in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.WANT may be incomplete. When this step was stopped there were 0 observations and 0 variables.
WARNING: Data set WORK.WANT was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
Tom
Super User Tom
Super User

So your dataset is not named DATA. Use the actual name of your existing dataset.

Also either your first step excluded the SEPARATED BY ' ' clause or your dataset only had one variable.

Reeza
Super User
Did the rest of the code run correctly? Show your full log, I suspect your issue is at the first step and it flowed through.
Reeza
Super User
Are you reading this data from a text file or from cards/datalines?
Tom
Super User Tom
Super User

If you also want to change the variables that look like numbers into numeric variables then you might be able to let PROC IMPORT help you.

filename csv temp;
data _null_;
  set have ;
  file csv dsd ;
  put (_all_) (+0);
run;
proc import datafile=csv dbms=csv out=want replace ;
  guessingrows=max;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2091 views
  • 2 likes
  • 3 in conversation