Dear,
I am using following code to create macro variables for data one.
But my actual data contains three treatments (trt1,trt2,trt3) and I am repeating the code three times to calculate macro variables. Is there any other solution to simplify code for data two; The placebo values should not included in Total.
data one;
input id trt1 $;
datalines;
1 10
2 10
3 20
4 30
5 20
6 30
7 30
;
proc sql;
create table NS as
select count(distinct id) as NS,trt1
from one
group by trt1;
quit;
data ns1;
set ns;
trt1=strip(trt1);
if trt1='10' then trt='A';
if trt1='20' then trt='B';
if trt1='30' then trt='C';
run;
data ns2;
set ns1 end=done;
Total + ns;
output;
if done;
ns = TOTAL;
trt='D';
trt1='Total';
output;
drop Total;
run;
data _null_;
set tnstfd11;
call symputx(trt,ns);
run;
data two;
input id trt1 $; trt2 $ trt3 $
datalines;
1 10 20 30
2 10 30 20
3 20 10 place
4 30 10 place
5 20 30 place
6 30 20 place
7 30 20 place
8 10 30 20
;
;
How about next code:
data one;
input id trt1 $;
datalines;
1 10
2 10
3 20
4 30
5 20
6 30
7 30
;
run;
proc format;
value $trtx
'10' = 'A'
'20' = 'B'
'30' = 'C'
; run;
proc sql;
create table NS as
select count(distinct id) as NS,
strip(trt1) as trt1,
put(trt1,$trtx.) as trt
from one
group by trt1;
quit;
data ns2;
set ns end=done;
Total + ns;
output;
if done;
ns = TOTAL;
trt='D';
trt1='Total';
output;
drop Total;
run;
In case you have more values to convert - add those values to the format TRTX.
Having trt2, trt3 - add similar lines as trt1 to the sql step.
Having trt2, trt3 etc. - pay attemtion to next code:
proc format;
value $trtx
'10' = 'A'
'20' = 'B'
'30' = 'C'
other = '*' /* ???? */
; run;
proc sql;
create table NS as
select count(distinct id) as NS,
strip(trt1) as trt1,
put(trt1,$trtx.) as trt_1,
strip(trt2) as trt2,
put(trt2,$trtx.) as trt_2,
strip(trt3) as trt3,
put(trt3,$trtx.) as trt_3
from one
group by trt1;
quit;
in proc format - see other= row for missing predefined values/
I could not understand what macro variables you want to create.
trt is a result of trt1. How to you want to deal with trt2, trt3 ?
Your code contains:
data _null_;
set tnstfd11; /* where from is this dataset ??? */
call symputx(trt,ns);
run;
Your only macro-related statement is in
data _null_;
set tnstfd11;
call symputx(trt,ns);
run;
which uses a dataset you have not provided any information for.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.