BookmarkSubscribeRSS Feed
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7
Hi Dear,
Here is my coding. I want all possible combinations of the following class variables REPSEG AND REGION using Proc means. The following code work fine.But when the input dataset empty, I need zeros in OSBAL LIMIT COUNTCUST AND LNO with the all the possilbe combinaion of Class variable.

PROC MEANS DATA=FLEX COMPLETETYPES NOPRINT;
CLASS RPTSEG REGION / PRELOADFMT;
VAR OSBAL LIMIT COUNTCUST LNO;
TYPES RPTSEG * REGION;
FORMAT RPTSEG MKTSEG. REGION $REGION.;
OUTPUT OUT=FLEXDATA SUM= N= /AUTONAME;

Can any one advice any solution for my question.


thanks very much in advance for your help.


Thanks


Inp
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Your post appears to ask about how to generate observations in your output file, WORK.FLEXDATA, using PROC MEANS, however your input file, WORK.FLEX, happens to be empty.

How should PROC MEANS treat this condition and what would you expect to see generated in your output file? Maybe you can show an input and output (expected) file content?

By the way, I ran similar code with an empty input file and PROC MEANS does generate an empty output file.

Scott Barry
SBBWorks, Inc.

data flex;
retain rptseg . region ' ';
retain osbal limit countcust lno 0;
stop;
run;
PROC MEANS DATA=FLEX COMPLETETYPES NOPRINT;
CLASS RPTSEG REGION / PRELOADFMT;
VAR OSBAL LIMIT COUNTCUST LNO;
TYPES RPTSEG * REGION;
* FORMAT RPTSEG MKTSEG. REGION $REGION.;
OUTPUT OUT=FLEXDATA SUM= N= /AUTONAME;
run;
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7
Thanks Scott for your reponse.
But I am looking for non empty output dataset from proc means for the input empty dataset.

Here is my format for the class variable.
proc format
VALUE $REGION
'A','B','C','E' = 'ATLANTIC REGION'
'G','J','H' = 'QUEBEC REGION'
OTHER = 'REGION ERROR'
;
RUN;

PROC FORMAT;
VALUE MKTSEG
1='COMMERICAL '
2='SMALL BUSINESS'
;
run;

My expected resulst for the empy data set is as follows. All values are not alligned here; I tried my best to make allign. Since I put completetypes and PRELOADFMT. I expect, for any empyt dataset, the proc means to produce all possible values of class variables according to my format and the related var values to be zero or missing .

My target to produce a report either the dataset is empty or non empty. For non empty dataset it is working fine.
For empty dataset, I want to produce a report for my customer, for the following Business type and the region, the values(var ) are zero.



Thanks for the help again

Inp


OSBAL_ LIMIT_COUNTCUST_ LOANNO_
OBS RPTSEG REGION Sum Sum Sum Sum OSBAL_N LIMIT_N N LNO_N

1 COMMERICAL ATLANTIC REGION . . . . 0 0 0 0
2 COMMERICAL QUEBEC REGION . . . . 0 0 0 0
3 COMMERICAL REGION ERROR . . . . 0 0 0 0
4 SMALL BUSINESS ATLANTIC REGION . . . . 0 0 0 0
5 SMALL BUSINESS QUEBEC REGION . . . . 0 0 0 0
6 SMALL BUSINESS REGION ERROR . . . . 0 0 0 0
Flip
Fluorite | Level 6
It seems you are trying to get missing to equal zero. They are not the same thing. Proc Means could not produce zeros as that would not be correct.

Try checking if your input is empty, then setting zeros as input to proc means. Then the result would be zero.
deleted_user
Not applicable
You may add a data step view to append one missing record if the data set is empty. The view is just identical to the data set if not empty. I assumed same data structure regardless of emptyness. It works only because one of your formats doesn't cover the missing value.
/*
data flex;
format rptseg mktseg. region $region.;
length osbal limit countcust lno 8;
stop;
run;
data flex1 / view=flex1;
if _n_=1 then if 0 then set flex nobs=nobs;
if nobs>0 then set flex ;
run;
PROC MEANS DATA=FLEX1 COMPLETETYPES NOPRINT;
CLASS RPTSEG REGION / PRELOADFMT;
VAR OSBAL LIMIT COUNTCUST LNO;
TYPES RPTSEG * REGION;
FORMAT RPTSEG MKTSEG. REGION $REGION.;
OUTPUT OUT=FLEXDATA SUM= N= /AUTONAME;
RUN;
*/
Inp
Obsidian | Level 7 Inp
Obsidian | Level 7
Thanks so much Urchin,. Your are the man.
It worked perfectly what I want. I put the follow codes and removed the view.

data flex;
if _n_=1 then if 0 then set flex nobs=nobs;
if nobs>0 then set flex ;
run;

Thanks to Flip and Scott for sharing your knowledge.


thanks

Inp

sas-innovate-2024.png

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.

 

Register now!

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
  • 5 replies
  • 1477 views
  • 0 likes
  • 4 in conversation