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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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