Hello,
I have 4 observation,which having var1 as unique key,var2 can have only 2 values like A and B. How can i create two more separate variables so that one variable flag if var 2 has value 'A' and other will flag if var 2 has value 'B'. Sorry for my bad English.
It will help if you can post an example of the data you have and then the output you want.
Available Data
Clm ID Task Template
1 16
1 17
3 16
4 17
Desired Data
Clm ID TemNum16 TempNum17
1 Y Y
3 Y N
4 N Y
Please Suggest
Proc Transpose can do that, but you will need to add a step to but in the 'N's for the missing values.
data have ;
input id template @@;
dummy='Y';
cards4;
1 16 1 17 3 16 4 17
;;;;
proc transpose data=have out=want prefix=TempNum ;
by id ;
id template;
var dummy ;
run;
data want ;
set want ;
drop _name_;
array c TempNum: ;
do over c; c=coalescec(c,'N'); end;
run;
data have2;
set have;
if task = 16 then tempnum16 = "Y";
else tempnum16 = "N";
if task = 17 then tempnum17 = "Y";
else tempnum17 = "N";
run;
proc sql;
create table want as
select distinct clm_id, (min(tempnum16)) as tempnum16, (min(tempnum17)) as tempnum17
from have2
group by clm_id;
quit;
Normally I would use max rather than min, but Y comes after N, so you use min for the summary of the responses.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.