BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hasnat
Calcite | Level 5

Hi. Is there anyone out there who can help me how to further sort this data.

 

Data E1;
input KYGVKEY & FYYYYQ & EPSFIQ;
*Sample data given,

where KYGKEY=firm identifier, FYYYYQ=fiscal year and quarters, EPSFIQ= (an)earning per share;
CARDS;
1690 1980.0 0.06
1690 1980.1 0.06
1690 1980.3 0.07
1690 1980.4 0.14
1690 1981.0 0.08
1690 1981.1 0.09
1690 1981.3 0.11
1690 1981.4 0.04
1730 1980.0 0.10
1730 1980.1 0.15
1730 1980.3 0.08
1730 1980.4 0.22
1730 1981.0 1.08
1730 1981.1 0.19
1730 1981.3 1.11
1730 1981.4 0.04
;
RUN;

PROC PRINT DATA=E1;
RUN;
*Required is to sort/arrange this data by firm's identifier=KYGVKEY, and
cross-sectional quarters: 1st quarters from 1980 and 1981 comes first
and 2nd next and so on with corresponding EPSFIQ,
to compare EPSFIQ of each quarter with corresponding quarter of last year;

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @hasnat,

 

PROC SQL is quite good at sorting data in non-standard ways:

proc sql;
create table e1s as
select * from e1
order by kygvkey, scan(fyyyyq,2), scan(fyyyyq,1);
quit;

But in the long run it will be more convenient to split FYYYYQ into two separate variables for fiscal year and quarter, respectively.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @hasnat,

 

PROC SQL is quite good at sorting data in non-standard ways:

proc sql;
create table e1s as
select * from e1
order by kygvkey, scan(fyyyyq,2), scan(fyyyyq,1);
quit;

But in the long run it will be more convenient to split FYYYYQ into two separate variables for fiscal year and quarter, respectively.

hasnat
Calcite | Level 5

Hi thanks. the idea of dissecting the variable from the start was great as it had more than one million obs. I did that in excel and imported and everything worked well.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1166 views
  • 4 likes
  • 2 in conversation