BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASPhile
Quartz | Level 8


The below are expected values for a category
Category Values
LDH Normal
LDH > 1X Normal
LDH > 2X Normal
LDH > 3X Normal

 

But Data only has

Category Values Count
LDH Normal 56
LDH > 1X Normal 25


I would like to display entire expected values as below with counts 0 to those that are not present in data:
Category Values Count
LDH Normal 56
LDH > 1X Normal 25
LDH > 2X Normal 0
LDH > 3X Normal 0

I'm seeking for help on how to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Please make it possible to tell the difference between a variable name and the actual values. I am guessing here.

 

And which output you want.

You likely want the option of PRELOADFMT which will use a format definition to have the values not present in the data available.

 

Very few procedures will accept the option but Procs Means/ Summary, Tabulate and Report will. Here are examples with  Report and Means;

proc format library=work;
value $ldh
"LDH Normal"       ="LDH Normal"      
"LDH > 1X Normal"  ="LDH > 1X Normal" 
"LDH > 2X Normal"  ="LDH > 2X Normal" 
"LDH > 3X Normal"  ="LDH > 3X Normal" 
;
run;

data example;
   length ldh $17;
ldh="LDH Normal"      ; count=56; output;
ldh="LDH > 1X Normal" ; count=25; output;
;

options missing='0';
proc report data=example completerows;
   columns ldh count;
   define ldh /preloadfmt group ;
   format ldh $ldh.;
run;

proc means data=example sum completetypes;
   class ldh / preloadfmt  ;
   format ldh $ldh.;
   var count;
run;

One headache is that controlling the order of the output if the variable is character as the sort orders are not likely to be what you want. If your "LDH" variable is numeric then order=data may get the order you want.

 

Note that every proc that uses PRELOADFMT requires at least one other option such as order=data, completerows, completetypes, and such and the interactions can be vexing at times.

 

Since Proc Means/ Summary will create output sets you might be ahead of the game to use them to request the count as otherwise depending on the procedure getting a 0 for missing values may take other steps.

View solution in original post

3 REPLIES 3
LNEW
Obsidian | Level 7

With proc format you would have a repeated or overlap of values for 0.

The simplest way I saw from using your information was creating a dataset with a category variable.

data val;

input LDH;

datalines;

 

56

25

0

0

; run;

data val1;

length Category $15;

set val;

if LDH >25 then do; Category = "LDH Normal"; end;

if LDH = 25 then do; Category = "LDH > 1XNormal"; end;

if LDH = 0 then do; Category = "LDH > 2XNorma"; end;

if LDH = 0 then do; Category = "LDH > 3XNormal"; end;

 

run;

 

ballardw
Super User

Please make it possible to tell the difference between a variable name and the actual values. I am guessing here.

 

And which output you want.

You likely want the option of PRELOADFMT which will use a format definition to have the values not present in the data available.

 

Very few procedures will accept the option but Procs Means/ Summary, Tabulate and Report will. Here are examples with  Report and Means;

proc format library=work;
value $ldh
"LDH Normal"       ="LDH Normal"      
"LDH > 1X Normal"  ="LDH > 1X Normal" 
"LDH > 2X Normal"  ="LDH > 2X Normal" 
"LDH > 3X Normal"  ="LDH > 3X Normal" 
;
run;

data example;
   length ldh $17;
ldh="LDH Normal"      ; count=56; output;
ldh="LDH > 1X Normal" ; count=25; output;
;

options missing='0';
proc report data=example completerows;
   columns ldh count;
   define ldh /preloadfmt group ;
   format ldh $ldh.;
run;

proc means data=example sum completetypes;
   class ldh / preloadfmt  ;
   format ldh $ldh.;
   var count;
run;

One headache is that controlling the order of the output if the variable is character as the sort orders are not likely to be what you want. If your "LDH" variable is numeric then order=data may get the order you want.

 

Note that every proc that uses PRELOADFMT requires at least one other option such as order=data, completerows, completetypes, and such and the interactions can be vexing at times.

 

Since Proc Means/ Summary will create output sets you might be ahead of the game to use them to request the count as otherwise depending on the procedure getting a 0 for missing values may take other steps.

Ksharp
Super User

You want it be a table or a report ?

 

data level;
input CategoryValues $20.;
cards;
LDH Normal
LDH > 1X Normal
LDH > 2X Normal
LDH > 3X Normal
;
run;

data have;
input CategoryValues & :$20. Count;
cards;
LDH Normal   56
LDH > 1X Normal   25
;
run;
proc tabulate data=have classdata=level;
class CategoryValues;
var count;
table CategoryValues,count*sum=' ' /misstext='0';
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1859 views
  • 0 likes
  • 4 in conversation