BookmarkSubscribeRSS Feed
Freppa
Calcite | Level 5

 

Hello,

 

I have some trouble understanding how to set up some logic based on a list I have. 

The logic from the list, shown below, should be that it should be sequential, i.e 2016Q1-Q4, but if let's say, 2016Q1 and 2016Q3 is missing it should give an output that they are missing.

data test;
input x;
cards;
2016Q2
2016Q4
2017Q1
2017Q2
2017Q3
2017Q4
2018Q1
;
run;

 

The next step I am trying to figure out is that if I want to produce the next report (2018Q2) it should check that [CurrentYear][Q-1] and [CurrentYear-1][Q4] exists, if not it should give an output on what is missing.

 

Best regards,

Fredrik

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

First, set your data to be the correct format:

input quarter yyq9.;

From:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000204480.htm

 

Something like:

data test;
  informat x yyq9.;
  format x yyq9.;
  input x;
cards;
2016Q2
2016Q4
2017Q1
2017Q2
2017Q3
2017Q4
2018Q1
;
run;

data want;
  set test;
  if intck('qtr',lag(x),x) ne 1 then output;
run;

Not sure what exactly you want as output, so just guessed.

ballardw
Super User

@Freppa wrote:

 

Hello,

 

I have some trouble understanding how to set up some logic based on a list I have. 

The logic from the list, shown below, should be that it should be sequential, i.e 2016Q1-Q4, but if let's say, 2016Q1 and 2016Q3 is missing it should give an output that they are missing.

data test;
input x;
cards;
2016Q2
2016Q4
2017Q1
2017Q2
2017Q3
2017Q4
2018Q1
;
run;

 

The next step I am trying to figure out is that if I want to produce the next report (2018Q2) it should check that [CurrentYear][Q-1] and [CurrentYear-1][Q4] exists, if not it should give an output on what is missing.

 

Best regards,

Fredrik


It really helps to show exactly what you are expecting for output.

So I am guessing  perhaps you want a message in the log about missing?

data test;
  informat x yyq9.;
  format x yyq9.;
  input x;
  retain lastx;
  format lastx yyq9.;
  if intck('quarter',lastx,x)>1 then put "WARNING: Missing quarter between " lastx yyq9. ' and ' x yyq9.;
  lastx=x;
  drop lastx  ;
cards;
2016Q2
2016Q4
2017Q1
2017Q2
2017Q3
2017Q4
2018Q1
;
run;

 

 

And you need to provide more information related to "next report". Compare what and where? In another data set?

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1075 views
  • 0 likes
  • 3 in conversation