This widget could not be displayed.
This widget could not be displayed.
BookmarkSubscribeRSS Feed
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

Pulling only EM codes and trying to create a column to flag EM codes:

 

data EMpull;
set OUTPAT;
if cpt between '99201' and '99215' or between
'99241' and '99245'
or '99381' and '99397' or
'99354' and '99355'
or '99401' and '99412' then EMflag="EM";
run;

18 REPLIES 18
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

What is your question?

--
Paige Miller
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

I figured it out. Was just trying to pull in all EM code data. 

 

Now I'm trying to split them into two quarters - 1/1/2021 - 3/31/2021 = Q1 and 4/1/2021 - 6/30/2021 i= Q2.  Where would I do that in this data set?

 

data EMpull;
set OUTPAT;
where ( '99201' <= cpt <= '99215')
or (cpt between '99241' and '99245')
or (cpt between '99381' and '99397')
or (cpt between '99354' and '99355')
or (cpt between '99401' and '99412');
run;

 

Thank you,

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
data EMpull;
set OUTPAT;
where ( '99201' <= cpt <= '99215')
or (cpt between '99241' and '99245')
or (cpt between '99381' and '99397')
or (cpt between '99354' and '99355')
or (cpt between '99401' and '99412');

Quarter = put(date, yyq6.);
QuarterNumber = QTR(date);

run;

 
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

I'm trying to create a a Q! and Q2 date range.  How do i create that first?

 

Q1 = 1/1/2021 thru 3/31/2021 and Q2 = 4/1/2021-6/30/2021

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
What does that mean in terms of a data set? My assumption was you had a date variable that you want to categorize rows as Q1/Q2.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

Yes I have two date ranges to split into quarters - Q1 and Q2.

 

This is what I have:

 

data EMpull;
set OUTPAT;
where ( '99201' <= cpt <= '99215')
or (cpt between '99241' and '99245')
or (cpt between '99381' and '99397')
or (cpt between '99354' and '99355')
or (cpt between '99401' and '99412');

 

if ('01Jan2021' <= eventDate <= '31Mar2021') THEN Q1;
else if ('01Apr2021' <= eventDate <= '30Jun2021') THEN Q2;

RUN;

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

Yes I have two date ranges to split into quarters - Q1 and Q2.

 

This is what I have:

 

data EMpull;
set OUTPAT;
where ( '99201' <= cpt <= '99215')
or (cpt between '99241' and '99245')
or (cpt between '99381' and '99397')
or (cpt between '99354' and '99355')
or (cpt between '99401' and '99412');

 

if ('01Jan2021' <= eventDate <= '31Mar2021') THEN Q1;
else if ('01Apr2021' <= eventDate <= '30Jun2021') THEN Q2;

RUN;

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

I just want a column called "QTR" then in that column for each date range should say either Q1 or Q2

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
Did you try the code I posted? What did you get?
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

it gives me this error:

 

Quarter=2021-05 QuarterNumber=. _ERROR_=1 _N_=1

 

It's not showing the Q1 or Q2 or anything in the data for that column

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
data EMpull;
set OUTPAT;
where ( '99201' <= cpt <= '99215')
or (cpt between '99241' and '99245')
or (cpt between '99381' and '99397')
or (cpt between '99354' and '99355')
or (cpt between '99401' and '99412');

 
*brute force method - not recommended;
if ('01Jan2021' <= eventDate <= '31Mar2021') THEN QTR="Q1";
else if ('01Apr2021' <= eventDate <= '30Jun2021') THEN QTR="Q2";

*better way;
QTR=catt('Q', qtr(eventDate));

RUN;

Fully tested example:

data stocks;
set sashelp.stocks;
where stock = 'IBM';
QTR=catt("Q", qtr(date));
YEAR_QTR = put(date, yyq6.);
keep date QTR YEAR_QTR;
run;

@anonymous_user wrote:

it gives me this error:

 

Quarter=2021-05 QuarterNumber=. _ERROR_=1 _N_=1

 

It's not showing the Q1 or Q2 or anything in the data for that column


 

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

Ok , how do you create the actual date range?

 

Like for Q1 = 1/1/2021-3/31/2021 and Q2 is 4/1/2021-6/30/2021.

 

I tried doing between operators and it doesn't work.  

 

Sorry for my ignorance, I need this laid out in lay terms.

 

 

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

This is what I've done with the example you provided (the output isnt making sense):

data EMpull;
set OUTPAT;
where ( '99201' <= cpt <= '99215')
or (cpt between '99241' and '99245')
or (cpt between '99381' and '99397')
or (cpt between '99354' and '99355')
or (cpt between '99401' and '99412');

QTR=catt('Q1', qtr('01Jan2021' <= eventDate <= '31Mar2021'));
/*catt('Q2', qtr('01Apr2021' <= eventDate <= '30Jun2021'));*/
YEAR_QTR = put(('01Jan2021' <= eventDate <= '31Mar2021'), yyq6.);
RUN;

This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.
This widget could not be displayed.

@anonymous_user wrote:

...

QTR=catt('Q1', qtr('01Jan2021' <= eventDate <= '31Mar2021'));

...

YEAR_QTR = put(('01Jan2021' <= eventDate <= '31Mar2021'), yyq6.);

...

The QTR() function operates on DATE values, but you passed it a BOOLEAN value (1=true 0=false) instead.

The YYQ. format operates on DATE values, but you also passed it a BOOLEAN value.

Since 0 and 1 are the first and second day of 1960 your code is equivalent to:

QTR='Q11';
YEAR_QTR = '1960Q1';

Why not try:

QTR=qtr(eventDate);
YEAR_QTR = put(eventDate,yyq6.);

Then if you want to limit the data to values in first two quarters of 2021 you could add:

if year_qtr in ('2021Q1' '2021Q2');

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 18 replies
  • 2655 views
  • 0 likes
  • 4 in conversation
This widget could not be displayed.
This widget could not be displayed.