BookmarkSubscribeRSS Feed
sas_lak
Quartz | Level 8


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 .........!

4 REPLIES 4
Loko
Barite | Level 11

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;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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?

sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10

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.

data_null__
Jade | Level 19

12-3-2014 2-20-55 PM.png

data have;
   input (var1-var3) ($);
   cards;
NAME1  NAME2  NAME3
XXXXX  YYYYY  ZZZZZ
AAAAA  BBBBB  CCCCC
;;;;
   run;
proc transpose data=have out=trans1;
   var var:;
   run;
proc print;
  
run;
proc transpose data=trans1 out=trans2(drop=_name_);
   id col1;
   var col2 col3;
   run;
proc print;
  
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 884 views
  • 6 likes
  • 5 in conversation