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

I'm currently having an issue where standard SAS formats (ex. MMDDYY8.) give an error message saying they can't be found or could not be loaded. This issue is only happening with one data set, I am able to use these formats in other datasets without a problem. Based on this link I think I need to redefine my format library, but I can't find the library with the default SAS formats in it, just the user-created ones. Where are the default formats located and how do I write a path to them if they're within SAS?

 

 

For reference, here's the relevant bit of code and error message. I have variables for year and quarter, and I need to create a time variable from them so I can plot trends against time. If anyone has another way of achieving this without using a date format that would be great as well.

 

data pwid.work;
	set pwid.work;
	input period $yyq6.;
	period=catx("Q",year,quarter);
run

 Capture.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@megsredl wrote:

The issue is I don't have a date variable. Right now I have two string variables, one for quarter and one for year. I can easily convert those to numeric, but I'm having trouble formatting them so SAS reads it as a date.


In that case generate a new string in the right style and use INPUT() function to convert it into a date.  Attach an appropriate date format to it to make it friendly for humans.

datevar=input(cats(year,'Q',qtr),yyq6.);
format datevar yyq6.;

View solution in original post

9 REPLIES 9
data_null__
Jade | Level 19
is PERIOD character?
megsredl
Obsidian | Level 7

Yes, per the SAS documentation I believe it should have the year and the quarter separated by a "Q".

Tom
Super User Tom
Super User

Make sure to use formats and informats that are appropriate for the type of values you are working with.  Formats convert values into text and informats convert text into values.  A character informat converts the text into new text values. A numeric informat converts them into numebers. A character format converts text into new text values. A numeric format converts numbers into text.  Note SAS stores date, time and datetime values as numbers.

 

I suspect that this real issue is caused by SAS trying to be helpful.  If you try to attach a format of the wrong type to a variable SAS will instead look for a format of the right type with the same name.

So there is no character format named $MMDDYY. Nor any character informat named $YYQ.

megsredl
Obsidian | Level 7

Thanks, I had a feeling that at least part of the problem was me mixing up formats and informats. What is the proper way to turn quarters into time data then? I've looked at the documentation for the YYQ informat and I'm still getting the syntax wrong.

Tom
Super User Tom
Super User

Your original data step was trying to use an INPUT statement which was a mistake because there was no source of lines of text to input from.

 

What do you want to create? 

What do you have?

 

If you want a character string that looks like 2019Q1 and you have a date value then use a PUT() function with the date value and the  YYQ6. format.  Although depending on how you are using it might not need to make a new variable and could just use the current date variable with a different format. Like this:

proc freq data=have;
  tables datevar ;
  format datevar yyq6.;
run;

 

megsredl
Obsidian | Level 7

The issue is I don't have a date variable. Right now I have two string variables, one for quarter and one for year. I can easily convert those to numeric, but I'm having trouble formatting them so SAS reads it as a date.

Tom
Super User Tom
Super User

@megsredl wrote:

The issue is I don't have a date variable. Right now I have two string variables, one for quarter and one for year. I can easily convert those to numeric, but I'm having trouble formatting them so SAS reads it as a date.


In that case generate a new string in the right style and use INPUT() function to convert it into a date.  Attach an appropriate date format to it to make it friendly for humans.

datevar=input(cats(year,'Q',qtr),yyq6.);
format datevar yyq6.;
megsredl
Obsidian | Level 7

Thank you so much! I've spent way too long trying to sort this out, but I finally get why my code wasn't working. I really appreciate the help, thank you for taking the time to chat with me about this!

Kurt_Bremser
Super User

@megsredl wrote:

I'm currently having an issue where standard SAS formats (ex. MMDDYY8.) give an error message saying they can't be found or could not be loaded. This issue is only happening with one data set, I am able to use these formats in other datasets without a problem. Based on this link I think I need to redefine my format library, but I can't find the library with the default SAS formats in it, just the user-created ones. Where are the default formats located and how do I write a path to them if they're within SAS?

 

 

For reference, here's the relevant bit of code and error message. I have variables for year and quarter, and I need to create a time variable from them so I can plot trends against time. If anyone has another way of achieving this without using a date format that would be great as well.

 

data pwid.work;
	set pwid.work;
	input period $yyq6.;
	period=catx("Q",year,quarter);
run

 Capture.PNG


Your code makes no sense. The input statement is for reading from external files, but you have no infile statement to sssign such a file.

If you want to convert data existing in the dataset named in the set statement, you need to use the input() function.

The YYQ informat is numeric, so you must not use the dollar sign, which denotes character formats/informats.

And you need to make up your mind about what you want to store in period: either a SAS date, which is numeric, or a string (character).

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 3417 views
  • 2 likes
  • 4 in conversation