DATA Step, Macro, Functions and more

I want empty dataset to be worked in Proc means.

Reply
Frequent Contributor
Frequent Contributor
Posts: 81

I want empty dataset to be worked in Proc means.

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
Super Contributor
Super Contributor
Posts: 3,174

Re: I want empty dataset to be worked in Proc means.

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;
Frequent Contributor
Frequent Contributor
Posts: 81

Re: I want empty dataset to be worked in Proc means.

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
Super Contributor
Posts: 359

Re: I want empty dataset to be worked in Proc means.

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.
N/A
Posts: 0

Re: I want empty dataset to be worked in Proc means.

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;
*/
Frequent Contributor
Frequent Contributor
Posts: 81

Re: I want empty dataset to be worked in Proc means.

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
Ask a Question
Discussion stats
  • 5 replies
  • 308 views
  • 0 likes
  • 4 in conversation