I have a variable called qy that looks like:
2008 Q1
2008 Q1
2009 Q2
2009 Q2
2009 Q3
2009 Q4
2009 Q4
2009 Q4
How can I set it in proper SAS format?
Ok. Do like this then
data have;
input qy $&;
datalines;
2008 Q1
2008 Q1
2009 Q2
2009 Q2
2009 Q3
2009 Q4
2009 Q4
2009 Q4
;
data want;
set have;
dt=input(compress(qy), yyq7.);
format dt date9.;
run;
Result:
qy dt 2008 Q1 01JAN2008 2008 Q1 01JAN2008 2009 Q2 01APR2009 2009 Q2 01APR2009 2009 Q3 01JUL2009 2009 Q4 01OCT2009 2009 Q4 01OCT2009 2009 Q4 01OCT2009
What do you consider a 'proper' SAS format?
Also, is this a character variable?
How do I view whether it is a character variable?
in the "Alphabetic List of Variables and Attributes" section of the output from
proc contents data=YourDataSetHere;
run;
It says it is a character
Ok. Do like this then
data have;
input qy $&;
datalines;
2008 Q1
2008 Q1
2009 Q2
2009 Q2
2009 Q3
2009 Q4
2009 Q4
2009 Q4
;
data want;
set have;
dt=input(compress(qy), yyq7.);
format dt date9.;
run;
Result:
qy dt 2008 Q1 01JAN2008 2008 Q1 01JAN2008 2009 Q2 01APR2009 2009 Q2 01APR2009 2009 Q3 01JUL2009 2009 Q4 01OCT2009 2009 Q4 01OCT2009 2009 Q4 01OCT2009
My initial dataset has over 8000 rows but when I run your code it gets reduced to only 10 rows.. Why is this the case? How can I fix it?
What does your log say?
@adrfinance wrote:
My initial dataset has over 8000 rows but when I run your code it gets reduced to only 10 rows.. Why is this the case? How can I fix it?
Copy the code with the messages from the LOG. Paste into a code box opened on the forum using the {I} icon.
Why? Need code and info that will be in the log.
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!
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.