Hi everyone, after doing proc freq to a demog dataset I obtain new4f:
agex treat Sex COUNT
13-24 drug F 4
13-24 drug M 2
13-24 PLA F 2
13-24 PLA M 4
less than 13 drug F 2
less than 13 drug M 2
less than 13 PLA F 1
less than 13 PLA M 2
Then, after doing proc sort and proc transpose I would expected the next datase *:
proc sort data=new4f out=new4fs;
by agex;
run;
proc transpose data=new4fs out=new4fst (drop=_label_ _name_);
by agex;
id treat sex;
var count;
run;
I would expected somethign like :
*dataset new4fst
agex drugf drugm plaf plam
13-24 4 2 2 4
less than 13 2 2 1 2
but, windows sas log shown the next error:
151 by agex ;
152 id treat sex;
---
22
-
200
ERROR 22-322: Expecting ;.
ERROR 200-322: The symbol is not recognized and will be ignored.
what I am doing wrong?
Thanks in advance.
V
how about:
data have;
input agex $20. treat $ Sex $ COUNT;
cards;
13-24 drug F 4
13-24 drug M 2
13-24 PLA F 2
13-24 PLA M 4
less than 13 drug F 2
less than 13 drug M 2
less than 13 PLA F 1
less than 13 PLA M 2
;
run;
data temp;
set have;
two=cats(treat,sex);
run;
proc transpose data=temp out=want(drop=_:) ;
by agex;
var count;
id two;
run;
proc print;run;
drug drug
Obs agex F M PLAF PLAM
1 13-24 4 2 2 4
2 less than 13 2 2 1 2
Linlin
how about:
data have;
input agex $20. treat $ Sex $ COUNT;
cards;
13-24 drug F 4
13-24 drug M 2
13-24 PLA F 2
13-24 PLA M 4
less than 13 drug F 2
less than 13 drug M 2
less than 13 PLA F 1
less than 13 PLA M 2
;
run;
data temp;
set have;
two=cats(treat,sex);
run;
proc transpose data=temp out=want(drop=_:) ;
by agex;
var count;
id two;
run;
proc print;run;
drug drug
Obs agex F M PLAF PLAM
1 13-24 4 2 2 4
2 less than 13 2 2 1 2
Linlin
It is very strange. I tested your code. No problem.
data have; input agex $20. treat $ Sex $ COUNT; cards; 13-24 drug F 4 13-24 drug M 2 13-24 PLA F 2 13-24 PLA M 4 less than 13 drug F 2 less than 13 drug M 2 less than 13 PLA F 1 less than 13 PLA M 2 ; run; proc transpose data=have out=want(drop=_:) ; by agex; var count; id treat sex; run;
Ksharp
hi ... two ID variables, online doc does say "one or more" ...
ID variable(s);
variable(s) names one or more variables whose formatted values are used to form the names of the variables in the output data set.
and ...
nice solution that doesn't require the prior concatenation of the variable values
One or more is new feature in SAS 9.2.
It works to me too. Thanks
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.