Hi All,
I need to drop variables and set First observation as a variables.
Ex:-
VARIABLES : - VAR1 VAR2 VAR3
OBSERVATION : - NAME1 NAME2 NAME3
XXXXX YYYYY ZZZZZ
AAAAA BBBBB CCCCC
OUTPUT LIKE : - NAME1 NAME2 NAME3
XXXXX YYYYY ZZZZZ
AAAAA BBBBB CCCCC
Thanks in advance .........!
Hello,
One solution:
data have;
input (VAR1 VAR2 VAR3 ) ($);
datalines;
NAME1 NAME2 NAME3
XXXXX YYYYY ZZZZZ
AAAAA BBBBB CCCCC
;
data _null_;
set have (obs=1);
array charall{*} _character_;
length x $ 80;
do i=1 to dim(charall);
x=cat(strip(x),'rename ',vname(charall{i}),'=',strip(charall{i}),';');
end;
call symput('newvar',x);
run;
data want;
&newvar;
set have(firstobs=2);
run;
How are you arriving at your input dataset as it appears like an import data where getnames=no. I would suggest you address this in your actual import code. I would recommend not using proc import to start with. Write a datastep and do the work yourself, gives far more control. The way you are doing it may lead to problems, for instance do you check to see if the data is a valid SAS name?
Consider investigating the merits with using PROC TRANSPOSE as well as DATA step processing to isolate in a separate SAS dataset/member those observations meaningful to your objective (resulting output dataset variable/column subset).
Scott Barry
SBBWorks, Inc.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.