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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.