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
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.
@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?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.