Hello programmers,
I have a sas output that i want to format and change into another format using a put statement.
The SAS output and how i want them to look like is in the attached photo.
Died is coded as (Yes/No =1/0). I have attached the codes that i ran. It's giving me all sorts of error and i thing it's a problem with the formatting.
Data sasoutput;
input tc Tn $ Value LowerCL UpperCL death COUNT PERCENT;
datalines;
1 Trouble with falling asleep 0.9622 0.7409 1.2497 1 424 16.8656
2 Trouble with waking during night 0.9019 0.7003 1.1617 1 424 16.8656
3 Trouble with waking too early 0.856 0.6434 1.139 1 424 16.879
;run;
data null ; set sasoutput; by tc tn;
options nodate nonumber;
file print notitles ;
If _N_ =1 then do;
put @45 'Died ' ;
put @45 ' N' @50 ' (%)';
end;
if first.tc then put / tn $33. @;
put @35 value valuefm. @45 Count 4. @50 '(' percent 5.2 ')'
;
run;
Just to clarify, did you create the first data set for the question or is that part of your code? Because it will not work. SAS assumes that the delimiter is space, and you have spaces in the second field (tn), the string with trouble. Also, the variable will only be 8 bytes long, so your full text will be truncated. The rest of your numeric variables will be missing, because SAS will try to put the string "with" into to variable "value" and that will be translated to missing.
Just to clarify, did you create the first data set for the question or is that part of your code? Because it will not work. SAS assumes that the delimiter is space, and you have spaces in the second field (tn), the string with trouble. Also, the variable will only be 8 bytes long, so your full text will be truncated. The rest of your numeric variables will be missing, because SAS will try to put the string "with" into to variable "value" and that will be translated to missing.
You might want to look at the Report Writing Interface which creates "nice" ods tables instead of the plain text that FILE print uses.
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 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.