BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
nnl3256
Obsidian | Level 7

Thanks! it works if the date variable was treated ad in DATETIME value.

qtr(datepart(datetime_value))

 

View solution in original post

4 REPLIES 4
nnl3256
Obsidian | Level 7

Pieces of code work before, but don't work now. The data test from SQL server and imported in csv format; test is subset of csv, containing 2 rows.

mif_data_reporting_dt is numeric in datetime 16 format. Attached test table and error message.  Thanks in advance!

proc import out=csv
datafile="F:\Shared\CMIP\Run81_sas_in.txt"
dbms=csv replace;
getnames=Yes;
run;

data new_data; set test; rptqtr=qtr(mif_data_reporting_dt); rptyr=year(mif_data_reporting_dt); run;

 

Tom
Super User Tom
Super User

I don't understand. 

Why are you creating dataset CSV in the first step and then reading from dataset TEST in the second step?

 

If you have a CSV file then just write a data step to read it and you will have full control over how the variables are defined.

Tom
Super User Tom
Super User

1,972,252,800 is not a valid date value.  With an average of 365.25 days per year that would be past the year 5 million.

 

734  data  test;
735    date=1972252800 ;
736    year = 1960 + int(date/365.25);
737
738    put date=comma32. year=comma32. ;
739    put date=datetime20.;
740  run;

date=1,972,252,800 year=5,401,693
date=01JUL2022:00:00:00

Probably your variable is actually a DATETIME value instead of a DATE value.  To find a QUARTER from a DATETIME value first convert the number of seconds to number of days.

 

qtr(datepart(datetime_value))

 

nnl3256
Obsidian | Level 7

Thanks! it works if the date variable was treated ad in DATETIME value.

qtr(datepart(datetime_value))

 

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
  • 690 views
  • 0 likes
  • 2 in conversation