BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mrinmoy
Obsidian | Level 7
Q1.I am running the below code snippets to get the b_date from Birth_Date 
 
data birth;
set credit card;
b_date= input(Birth_Date,10.);
format b_date date9.
run;
 
Why for Birth_Date 01/08/1966, b_date = 22JAN1960 ?
 
Q2. Running the below code Snippets.
 
data birth;
set credit card;
b_date= input(Birth_Date,10.);
run:
 
Why for Birth_Date 01/08/1966,  b_date = 21?
 
Q3) Running the below code Snippets.
 
data birth;
set credit card;
b_date= put(Birth_Date,10.);
run:
 
Why for Birth_Date 01/08/1966,  b_date = 2199?
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Adding to @ccarel

 

The value of Birth_date apparently is already a SAS date value. Run proc contents on your data set and I bet you see Birth_date has Format mmddyy10.

 

What you did with this code:

b_date= input(Birth_date,10.);

was ask SAS to convert the existing value of Birth_date to a string value that the INPUT function requires. The unformatted value of 08Jan1966 is 2199. When SAS does the requested conversion it uses the best12. format so the resulting string 12 characters long with a value of 8 blanks followed by 2199. Then you tell SAS to read that value with 10. format so it reads the first 10 characters. The only numerals there are 21 so the result is 21. When you format that as a date you get 22 Jan 1960 because 0 is 1 Jan 1960 and dates are number of days from 1 Jan 1960. So add 21 = 22 Jan 1960.

 

If your value had actually been the string '01/08/1966' there would have been an error because that is not valid to read with the 10. informat.

 

Your log when you ran the code would have message about "Numeric values have been converted to character values at the places given by :

(Line):(Column).

the line and column shown would point to the location of Birth_date in the input function argument.

 

 

View solution in original post

11 REPLIES 11
PeterClemmensen
Tourmaline | Level 20

Can you provide some sample data?

mrinmoy
Obsidian | Level 7

can you please try with the date which has been given in the question 

Kurt_Bremser
Super User

You need to give us a sample of your datasets credit and card (as yout set statement adresses those two datasets).

We need this to see the actual values and the variable types and attributes.

Provide the data in a data step; a macro that converts your dataset to a data step for posting is found here:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

When posting, use the "little running man" or {i} icons. These preserve formatting and prevent reformatting of supposed smileys etc.

mrinmoy
Obsidian | Level 7

PFA for sample data set

Kurt_Bremser
Super User

The problem is that a csv file does not convey column attributes in any way, which are essential in getting the right answers.

Or do you mean that you do not yet have a SAS dataset and need proper import code for the csv also?

mrinmoy
Obsidian | Level 7

The data set i have importeed correctly but I am not understanding why I am getting different out put while using put and input 

please help me on that

Kurt_Bremser
Super User

Show the code with which you imported the csv, so we can recreate your dataset.

Or use the macro I previously mentioned to convert your dataset into a data step for posting here.

Astounding
PROC Star

Board monitors,

 

Perhaps it's time to compare this to:

 

https://communities.sas.com/t5/General-SAS-Programming/PUT-and-INPUT/m-p/345080#M44559https://commun...

 

Looks like there's a homework assignment here.

ccarel
Fluorite | Level 6
 
Q1.I am running the below code snippets to get the b_date from Birth_Date 
 
data birth;
set credit card;
b_date= input(Birth_Date,10.);
format b_date date9.
run;
 
Why for Birth_Date 01/08/1966, b_date = 22JAN1960 ?
 
Answer: The b_date is 22JAN1960 b/c that is the DATE9. format that you requested in the code.  You also need a semicolon (;) after DATE9.
 
 
ballardw
Super User

Adding to @ccarel

 

The value of Birth_date apparently is already a SAS date value. Run proc contents on your data set and I bet you see Birth_date has Format mmddyy10.

 

What you did with this code:

b_date= input(Birth_date,10.);

was ask SAS to convert the existing value of Birth_date to a string value that the INPUT function requires. The unformatted value of 08Jan1966 is 2199. When SAS does the requested conversion it uses the best12. format so the resulting string 12 characters long with a value of 8 blanks followed by 2199. Then you tell SAS to read that value with 10. format so it reads the first 10 characters. The only numerals there are 21 so the result is 21. When you format that as a date you get 22 Jan 1960 because 0 is 1 Jan 1960 and dates are number of days from 1 Jan 1960. So add 21 = 22 Jan 1960.

 

If your value had actually been the string '01/08/1966' there would have been an error because that is not valid to read with the 10. informat.

 

Your log when you ran the code would have message about "Numeric values have been converted to character values at the places given by :

(Line):(Column).

the line and column shown would point to the location of Birth_date in the input function argument.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 11 replies
  • 1853 views
  • 1 like
  • 6 in conversation