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-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 904 views
  • 0 likes
  • 2 in conversation