Inside my project, I'd like to create a summary table in which I represent for each indicator the score relating to a specific date.
The problem is that the correct data type for almost all indicators is PERCENTN9.2 while for one is 6.
In other words, my output should be
Indicator Score
1 12,86%
2 110,96%
3 4.853
4 30,64%
Is it possible to obtain this output?
Hi
If it is for printed output, you can use Proc REPORT and the CALL DEFINE routine to achive this, see example below.
data have;
input
Indicator
Score
;
cards;
1 0.1286
2 1.1096
3 4.853
4 0.3064
;
proc report data=have;
column indicator score _dummy;
define indicator / display;
define score / display;
define _dummy / computed noprint;
compute _dummy;
if indicator = 3 then do;
call define("score", "format", "8.4");
end;
else do;
call define("score", "format", "percentn9.2");
end;
endcomp;
run;
Yes. What youwould do is create a character variable (remember character variables can hold anything) and then put each of your values into the correct format into there and print that (score_char in the below will contain the mismatched formats):
data want (keep=indicator score_char); set have; length score_char $200; score_char=ifc(indicator=3,put(score,5.3),put(score,percent5.)); run;
Hi
If it is for printed output, you can use Proc REPORT and the CALL DEFINE routine to achive this, see example below.
data have;
input
Indicator
Score
;
cards;
1 0.1286
2 1.1096
3 4.853
4 0.3064
;
proc report data=have;
column indicator score _dummy;
define indicator / display;
define score / display;
define _dummy / computed noprint;
compute _dummy;
if indicator = 3 then do;
call define("score", "format", "8.4");
end;
else do;
call define("score", "format", "percentn9.2");
end;
endcomp;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.