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

Hey guys,

 

I have a pipe-delimited text file that I'm trying to import to a SAS table and the formatting is not going particularly well.

I have a column labeled "QRTR" which is essentially in this format: "2014-2".  This value represents the 2nd quarter of 2014.

Is there a way for me to convert this charvar to a numeric with an INPUT statement, and then convert the numeric to its' correct format using yyqd.?  

 

Thank you,

Sean

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
data example;
   x = "2014-2";
   date= input(translate(x,'Q','-'),yyq6.);
   format date yyq6.;
run;

The resulting date acutally is assumed to be the first day the calendar quarter. You can use date9. or other format to examine it if needed.

 

View solution in original post

4 REPLIES 4
Reeza
Super User

Read it in as character, replace - with Q and convert using ANYDTDTE informat.

 

data test;
informat date $8.;
input date $;
y = input(translate(date, "Q", "-"), anydtdte.);
format y yyqd.;
cards;
2012-3
2013-1
2014-2
2015-5
2016-1
;
run;
ballardw
Super User
data example;
   x = "2014-2";
   date= input(translate(x,'Q','-'),yyq6.);
   format date yyq6.;
run;

The resulting date acutally is assumed to be the first day the calendar quarter. You can use date9. or other format to examine it if needed.

 

soneil9
Calcite | Level 5

Thank you both!  I added in your code to my data step and it worked beautifully.

mkeintz
PROC Star
Then mark a solution
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2657 views
  • 1 like
  • 4 in conversation