Hi,
Previously we had a sas code to load the date values into the numeric column in database. Like in the sas dataset . the date value is 19720426 and when it is appending to the database which has numeric (11,0) datatype, it has been loaded as 4499.
Which format has been used in default in proc append for this conversion ??
Problem is now I want to use the same dataset and load into a text value .I want to have that date column as numeric. I tried with few format option, but no luck.
Please let me know to rectify this issue.
Which character value should arrive in the database for the SAS date value 1972-04-26?
@helannivas88 wrote:
Sorry, I dont want any char value. In the SAS dataset, the date value is 26Apr1972 but it was wrongly designed in the database for that date column as numeric data type , so the date value had been loaded as 4499 before.
From the same dataset, I want to create a .txt file using proc export. When I do that , 26Apr1972 has been loaded in the .txt file, which I dont want . I want to convert that date into numeric before loading into the .txt file.
A text file has no numbers, only text. TEXT.
Which means that the SAS number 19720426 and the SAS character value "19720426" will end up as the string 19720426 in the text file.
Proof:
data have;
date = "26apr1972"d;
format date yymmddn8.;
run;
filename a temp;
data _null_;
file a dlm="|";
set have;
d1 = put(date,yymmddn8.); /* character */
d2 = input(put(date,yymmddn8.),8.); /* number */
put date d1 d2;
run;
data check;
infile a;
input;
check = _infile_;
run;
@helannivas88 wrote:
Sorry, I dont want any char value. In the SAS dataset, the date value is 26Apr1972 but it was wrongly designed in the database for that date column as numeric data type , so the date value had been loaded as 4499 before.
From the same dataset, I want to create a .txt file using proc export. When I do that , 26Apr1972 has been loaded in the .txt file, which I dont want . I want to convert that date into numeric before loading into the .txt file.
A text file has no numbers, only text. TEXT.
Which means that the SAS number 19720426 and the SAS character value "19720426" will end up as the string 19720426 in the text file.
Proof:
data have;
date = "26apr1972"d;
format date yymmddn8.;
run;
filename a temp;
data _null_;
file a dlm="|";
set have;
d1 = put(date,yymmddn8.); /* character */
d2 = input(put(date,yymmddn8.),8.); /* number */
put date d1 d2;
run;
data check;
infile a;
input;
check = _infile_;
run;
@helannivas88 wrote:
Sorry, I dont want any char value. In the SAS dataset, the date value is 26Apr1972 but it was wrongly designed in the database for that date column as numeric data type , so the date value had been loaded as 4499 before.
From the same dataset, I want to create a .txt file using proc export. When I do that , 26Apr1972 has been loaded in the .txt file, which I dont want . I want to convert that date into numeric before loading into the .txt file.
There's a huge amount of mis-statements above. 26Apr1972 is represented in SAS (and many other softwares) as 4499. Dates must be numeric integers that represent the number of days since January 1, 1960, that's how 4499 is determined. So a numeric 4499 is correct.
As pointed out by @Kurt_Bremser, in a text file, everything is text. If you something that LOOKS LIKE a numeric integer in your text file, you can use the proper format in SAS when creating the text file, for example yymmdd8, which will make 4499 look like 19720426.
yymmddN8.
@helannivas88 wrote:
Previously we had a sas code to load the date values into the numeric column in database. Like in the sas dataset . the date value is 19720426 and when it is appending to the database which has numeric (11,0) datatype, it has been loaded as 4499.
19720426 is not a SAS date value.
It may represent April 26, 1972. If so, it must be converted to an actual SAS date value.
value=19720426;
datevalue = input(put(value,8.),yymmdd8.);
If you convert the value to an actual SAS date value, then I think this resolves the rest of your issues. But, I'll leave that up to you.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.