BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dapenDaniel
Obsidian | Level 7

Hi,

 

I have a dataset as below.

 

 

data have;
input name $ Var1 Var2 Var3 Var4;
datalines;
AA 0 0 0 1
AA 0 1 0 0
BB 0 0 1 0
BB 1 0 0 0
run;

 

 

I want the dataset as below.

 

ID          Var_Con

AA             0101

BB             1010

 

 

what program do I need to use? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
input name $ Var1 Var2 Var3 Var4;
datalines;
AA 0 0 0 1 
AA 0 1 0 0
BB 0 0 1 0 
BB 1 0 0 0
;
run;
proc summary data=have nway;
class name;
var var1-var4;
output out=temp(drop=_:) sum=;
run;

data want;
 set temp;
 length var_con $4;
 var_con=cats(of var1-var4);
 keep name var_con;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data have;
input name $ Var1 Var2 Var3 Var4;
datalines;
AA 0 0 0 1 
AA 0 1 0 0
BB 0 0 1 0 
BB 1 0 0 0
;
run;
proc summary data=have nway;
class name;
var var1-var4;
output out=temp(drop=_:) sum=;
run;

data want;
 set temp;
 length var_con $4;
 var_con=cats(of var1-var4);
 keep name var_con;
run;
yabwon
Onyx | Level 15

Maybe like this:

data have;
input name $ Var1 Var2 Var3 Var4;
datalines;
AA 0 0 0 1 
AA 0 1 0 0
BB 0 0 1 0 
BB 1 0 0 0
;
run;

data want;
  set have;
  by name;
  array A Var:;
  array B[4] _temporary_;

  do over A;
    B{_i_} + A;
  end;

  if last.name then
    do;
      var_con = cats(of B[*]);  
      output;
      call missing(of B[*]);
    end;
    keep name var_con;
run;

 

All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 598 views
  • 0 likes
  • 3 in conversation