I have data set with:
proc format;
value my_f 1="A"
2="B"
3="C"
4="D"
5="E";
run;
And i have programm
proc freq data=temp;
tables my_tables /nocum
out = temp_2;
run;
Result:
Name COUNT PERCENT
A 1 10
C 9 90
But i need:
Name COUNT PERCENT
A 1 10
B 0 0
C 9 90
D 0 0
E 0 0
Hello @Konstantin123,
Try this:
data allcat;
do name=1 to 5;
output;
end;
run;
data want;
merge temp_2(in=t)
allcat;
by name;
if ~t then do;
count=0;
percent=0;
end;
run;
Please note that I used NAME as the variable name. In your PROC FREQ step it's called MY_TABLES, but in your output it appears as "Name."
Hello @Konstantin123,
Try this:
data allcat;
do name=1 to 5;
output;
end;
run;
data want;
merge temp_2(in=t)
allcat;
by name;
if ~t then do;
count=0;
percent=0;
end;
run;
Please note that I used NAME as the variable name. In your PROC FREQ step it's called MY_TABLES, but in your output it appears as "Name."
This should get you started:
proc tabulate data=temp;
class my_tables/ preloadfmt;
format my_tables my_f.;
table my_tables,n='Count' ColPctN='Percent'
/ printmiss misstext='0';
run;
The Preloadfmt only works with limited procedures, Report, Means and Tabulate, to show the appearance of formatted values not in your data. The Printmiss is one of a couple ways to get the missing values printed in the output. Misstext to show 0 instead of default period for missing values since you don't have anything to actually count.
Use proc tabulate or proc freq + weight w / zero . proc format; value my_f 1="A" 2="B" 3="C" 4="D" 5="E"; run; data have; input my_tables ; cards; 1 2 2 ; run; options missing=0; proc tabulate data=have; class my_tables /preloadfmt; format my_tables my_f.; table my_tables ,n pctn/printmiss; run; /**************************************/ data key; do my_tables=1 to 5; output; end; run; data want; set have(in=ina) key; w=ina; run; proc freq data=want; table my_tables; weight w/zero; run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.