BookmarkSubscribeRSS Feed
hasnat
Calcite | Level 5

Hi. 

Can someone help me how to sort this attached sample financial accounting data in SAS 9.4 or SAS Studio (the real data could be few hundred thousands obs). 

Link to the SAS file as i could not attach here: https://1drv.ms/f/s!AhVkgVJPuTkWh03K4IT_COxuKZwP

 

Let EPSFIQ be the representative of earnings of the firm 1690. I want to see how many times over the sample period the firm 1690 has consecutively reported earnings more than last quarter, and by 'consecutive' i expect the firm should have reported earnings more than last quarter 5 consecutive times for the earnings string to be considered as consecutive. So this period of 5 consecutive increased earnings can be called an earnings string. In other words, the condition for such strings is 5 consecutive increases in EPSFIQ.

I want to separate such earnings strings from the rest of the data. 

(Updated)

Thanks in advance for your time. 

4 REPLIES 4
Mar1ene
Obsidian | Level 7

hi Hasnat,

 

I'm not 100% sure I understand the requirement, but if I am correct, you can use the below and specify the output in the proc report by 'key'... I hope this helps...

 

proc sort data=SASxyz; by FYYYYQ;
data SASxyz1;
set SASxyz;
counter = _N_;
Key = ceil(counter/5);
run;

 

proc report data=SASxyz1 out=SASxyz2 (drop=_break_) nowd missing;
columns Key FYYYYQ EPSFIQ;
define Key/group;
define FYYYYQ/display;
define EPSFIQ/display;
run;

 

Output sample:

KeyFYYYYQEPSFIQ
11980.0999760.06
 1980.1999510.06
 1980.3000490.06
 1980.4000240.07
 1981.0999760.14
21981.1999510.16
 1981.3000490.21
 1981.4000240.19
 1982.0999760.24
 1982.1999510.24
31982.3000490.26
 1982.4000240.32
 1983.0999760.4
 1983.1999510.4
 1983.3000490.4

 

Kind Regards,

Marlene

 

hasnat
Calcite | Level 5

Hi. Thanks for your help and feedback. I ran your code and edited a bit but realized that description of the post was indeed not sufficient, I have elaborated further.  

Mar1ene
Obsidian | Level 7

Hi Hasnat,

 

I give up... LOL!  Guess the pro's should rather assist.  Give my below code a shot...

 

proc sort data=SASxyz; by FYYYYQ;
data SASxyz1 (drop=prev_EPSFIQ move_perc);
set SASxyz;
by FYYYYQ;
format prev_EPSFIQ 8.2 move_perc comma5.2;
prev_EPSFIQ = lag(EPSFIQ);
if prev_EPSFIQ in (.,0) then prev_EPSFIQ=EPSFIQ;
move_perc = ((EPSFIQ-prev_EPSFIQ)/prev_EPSFIQ)*100;
count + 1;
if move_perc<0 then count = 0;
run;

 

proc report data=SASxyz1 out=SASxyz2 (drop=_break_) nowd missing;
columns FYYYYQ count n;
define FYYYYQ/display;
define count/across;
where count ne 0;
run;

 

Go well!!

Marlene

hasnat
Calcite | Level 5

Hi Marlene!

Yes today my course coordinator spent a couple of hours and came up with desired results, your 'if' statement idea was incorporated. Once i do it myself, i would update here as well as i did not explicitly seek teacher's permission to share the code.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1227 views
  • 1 like
  • 2 in conversation