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

I have a MS SQL-Server table that contains a character field with date values representing a quarter year with the format YYYY-Q1.  The SAS provided informat YYQ. won't work because the field contains a hyphen (-) between the year and the quarter.

 

I have tried creating a picture informat, but with no success.

proc format;

picture yyqtr
low-high = "%Y-Q%q" (DATATYPE=datetime);

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

The picture syntax is only for formats.

If you want to create an informat, this works:

proc format;
  invalue nodash 's/-//' (regexpe)=[yyq6.];
data T;
  DATE=input('2020-Q1',nodash7.);
run;

 

 

View solution in original post

4 REPLIES 4
Reeza
Super User

Use COMPRESS() to remove the -?

 

want = input(compress(var, "-"), YYQ6.);

@Jim_Cooper_hmsa wrote:

I have a MS SQL-Server table that contains a character field with date values representing a quarter year with the format YYYY-Q1.  The SAS provided informat YYQ. won't work because the field contains a hyphen (-) between the year and the quarter.

 

I have tried creating a picture informat, but with no success.

proc format;

picture yyqtr
low-high = "%Y-Q%q" (DATATYPE=datetime);

run;


 

ChrisNZ
Tourmaline | Level 20

The picture syntax is only for formats.

If you want to create an informat, this works:

proc format;
  invalue nodash 's/-//' (regexpe)=[yyq6.];
data T;
  DATE=input('2020-Q1',nodash7.);
run;

 

 

Jim_Cooper_hmsa
Obsidian | Level 7

Chris,

 

This is very cool.  I think that I was approaching the problem from the wrong direction.  i should have been looking for an INVALUE solution instead of a PICTURE solution,  This is awesome.

 

Mahalo Nui

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1053 views
  • 5 likes
  • 3 in conversation