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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.