I'm running this code.
* show dataset info;
proc iml;
use sashelp.class;
show contents;
quit;
* show dataset missing;
proc iml;
use sashelp.class;
read all var _NUM_ into x[colname=nNames];
n = countn(x,"col");
nmiss = countmiss(x,"col");
ntotal = n + nmiss;
n_p = (n / ntotal) * 100;
nmiss_p = (nmiss / ntotal) * 100;
read all var _CHAR_ into x[colname=cNames];
c = countn(x,"col");
cmiss = countmiss(x,"col");
ctotal = c + cmiss;
c_p = (c / ctotal) * 100;
cmiss_p = (cmiss / ctotal) * 100;
close data.stl_2p;
Names = cNames || nNames;
colNames = {"Missing", "Not Missing"};
cnt = (cmiss_p // c_p) || (nmiss_p // n_p);
cnt = cnt`;
print cnt[r=Names c=colNames label="Percent(%)" format=5.2];
quit;
The output for "show contents" can be pasted nicely into comments, but the "print ..." table cannot.
Is there a way to format the results of the print statement to be similar to "show contents"?
I just want the table values to be aligned with the columns when I copy paste it into the comments.
Sure. you are probably copying from the HTML destination. You can preserve spacing by copying from the LISTING destination, which uses a monospace (fixed-width) font.
ods listing;
print cnt[r=Names c=colNames label="Percent(%)" format=5.2];
ods listing close;
You can now copy/paste the results from the Output window. If you can't find the Output window, tell us how you are running the code: SAS Studio? Enterprise Guide? Classic Windowing system (DMS)?
I normally use
proc format;
value $missfmt ' '='Missing' other='Not Missing';
value missfmt . ='Missing' other='Not Missing';
run;
proc freq data=sashelp.class;
format _NUMERIC_ missfmt.;
table _NUMERIC_ / missing;
format _CHAR_ $missfmt.;
table _CHAR_ / missing;
run;
But I wanted to keep all values in a single table.
If there is an easier method that does exactly this, then I'd like to use that.
However, my main problem is just getting a nicely aligned table that can be copy pasted back into the editor without first writing to another file.
I have a version here if you’d like that collects all the info cleanly.
https://gist.github.com/statgeek/2de1faf1644dc8160fe721056202f111
@ReezaThank you for sharing this.
Why not post it at IML forum ? @Rick_SAS is there .
Sure. you are probably copying from the HTML destination. You can preserve spacing by copying from the LISTING destination, which uses a monospace (fixed-width) font.
ods listing;
print cnt[r=Names c=colNames label="Percent(%)" format=5.2];
ods listing close;
You can now copy/paste the results from the Output window. If you can't find the Output window, tell us how you are running the code: SAS Studio? Enterprise Guide? Classic Windowing system (DMS)?
@Rick_SASThis output exactly what I was looking for. Thank you.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.