Help using Base SAS procedures

Find the same obs with Different months

Reply
N/A
Posts: 0

Find the same obs with Different months

Hi



data cus_mon;
input cus mon$ emi;
cards;
1 jan 20
2 jan 10
3 jan 20
1 feb 20
2 feb 20
3 feb 10
1 mar 20
2 mar 20
3 mar 20
run;

i want the no of customers paying the emi same amount in the months jan,feb and mar in this Dataset cusomer 1 is paying the same emi in all the three months like this i want the count of .No of customers paying the same amount in all the three months .

I am having 30,000 obs i sholud find this from that obs
Valued Guide
Posts: 2,177

Re: Find the same obs with Different months

Posted in reply to deleted_user
sql or data step?
Super Contributor
Super Contributor
Posts: 3,174

Re: Find the same obs with Different months

One suggestion is that you appear to be working with "character string" date-related data values (without a year supplied in the input) -- convert these to SAS numeric DATE type variables using the INPUT function in a SAS assignment statement - a DATA step approach likely, possibly assigning the current year using the YEAR( TODAY() ) functions. Then you can use the MONTH() if you need to reference one or more months as a logical group in your IF / THEN variable assignment logic.

Scott Barry
SBBWorks, Inc.
Super Contributor
Super Contributor
Posts: 3,174

Re: Find the same obs with Different months

The SAS support http://support.sas.com/ website has a wealth of SAS-hosted product documentation and also technical / conference contributed papers on these type of topics - some links pasted below for your reference and use:

Scott Barry
SBBWorks, Inc.

Working with Dates in the SAS System

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm


How the DATA Step Identifies BY Groups

Processing Observations in a BY Group

http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000761931.htm



A Hands-On Introduction to SAS® DATA Step Programming
Debbie Buck, D. B. & P. Associates, Houston, TX
http://www2.sas.com/proceedings/sugi30/134-30.pdf


SAS 9.2 DOC - Data Step Processing:
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm

Processing a DATA Step: A Walkthrough
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000961108.htm
N/A
Posts: 0

Re: Find the same obs with Different months

In DATA step
Valued Guide
Posts: 2,177

Re: Find the same obs with Different months

Posted in reply to deleted_user
since the chain is over only 3 months, it seems OK just to merge the 3 separate months and, if the amounts (emi) are the same, create a counter[pre]data counting( keep= cus emi1 ) ;
merge cus_mon( in=jan rename=( mon= mon1 emi= emi1 ) where=( mon1= 'jan'))
cus_mon( in=feb rename=( mon= mon2 emi= emi2 ) where=( mon2= 'feb'))
cus_mon( in=mar rename=( mon= mon3 emi= emi3 ) where=( mon3= 'mar') )
;
by cus ;
if jan and feb and mar and
emi1= emi2 and emi2=emi3 then output ;
run ;
proc print ;
run ; [/pre]
The count is the number of observations output to table COUNTING.

PeterC
Ask a Question
Discussion stats
  • 5 replies
  • 116 views
  • 0 likes
  • 3 in conversation