BookmarkSubscribeRSS Feed
Ross1010
Calcite | Level 5

hi

i'm new to sas so apologies if this is really easy but i want to total up the fields which have a condition in and those that have a blank in the field.  I have 4 conditions so a way to work out the total for condition 1 with/without something in field, then condition 2, condition 3 etc

 

Hope that makes sense


Cheers

 

Code i have so far is

 

 

rsubmit &UNIX;
data pol_trv_dims;
set DLItm.pol_trv_dims
(keep = POLKEY CONDITION1 CONDITION2 CONDITION3 CONDITION4);

run;
endrsubmit;

2 REPLIES 2
ballardw
Super User

@Ross1010 wrote:

hi

i'm new to sas so apologies if this is really easy but i want to total up the fields which have a condition in and those that have a blank in the field.  I have 4 conditions so a way to work out the total for condition 1 with/without something in field, then condition 2, condition 3 etc

 

Hope that makes sense


Cheers

 

Code i have so far is

 

 

rsubmit &UNIX;
data pol_trv_dims;
set DLItm.pol_trv_dims
(keep = POLKEY CONDITION1 CONDITION2 CONDITION3 CONDITION4);

run;
endrsubmit;


It really helps to show some actual example input data and what the end result should be. Provide some records that will exercise each of your rules.

 

You may want to try:

proc summary data=pol_trv_dims;
   class condition1 - condition4 /missing;
   output out=work.summary;
run;

The output data set will have combinations of the variables on the class statement, including one record for "missing", and a count of records in the variable _freq_. There will be another variable _type_ that indicates which set of combinations each record represents,

Type=0 will a total count of records, type=1 will be the summary for one variable only, expect the last one on the CLASS statement, 2, 3 and 4 would be each of the other variables on the class statement alone, higher numbers will represent different combinations. The largest value of _type_ will be all of the variables combined.

 

You can filter the data for other use on the value of _type_ to get the records you are interested.

 

Astounding
PROC Star

This might be a little more than you asked for, but it should all be useful:

 

proc format;
value $missfmt ' '='Blank' other='There';
run;

proc freq data=have;
tables condition1-condition4 / missing;
tables condition1*condition2*condition3*condition4 / list missing;
format condition1-condition4 $missfmt.;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1435 views
  • 0 likes
  • 3 in conversation