BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmnagasree
Calcite | Level 5
Data ds1; 
Input pid drug$ visit_date date9.; 
Format visit_date date9.; 
Cards; 
101 asp-05mg 12jan2005  
102 asp-10mg 14jan2005  
101 asp-05mg 18jan2005 
102 asp-10mg 12jan2005 
101 asp-05mg 21jan2005 
103 asp-15mg 12jan2005 
101 asp-05mg 30jan2005 
102 asp-10mg 12jan2005 
101 asp-05mg 23jan2005 
102 asp-10mg 12jan2005 
101 asp-05mg 11jan2005 
103 asp-15mg 12jan2005 
101 asp-05mg 15jan2005 
104 asp-20mg 12jan2005 
101 asp-05mg 16jan2005 
102 asp-10mg 12jan2005 
103 asp-15mg 12jan2005 
103 asp-15mg 12jan2005 
101 asp-05mg 15jan2005 
; 
Run; 

data f;
set ds1;
visit_date=date ;
informat date date10.;
format date date10.;
run;

i am unable to get the values in date variable.

please guide me.
thank you.
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

What is the purpose of the second data step?

data f;
  set ds1;
  visit_date=date ;
  informat date date10.;
  format date date10.;
run;

It looks like you are creating a new (and hence totally missing) variable and then using it to overwrite the variable VISIT_DATE that you read from the DS1 dataset.

Perhaps you meant to do this?

data f;
  set ds1;
  date = visit_date ;
  format date date9.;
run;

Not sure what value using a width of 10 does for the DATE format.  DATE9 will print with four digit years.  DATE11 will add hyphens around the month.

Also not sure what value is added by assigning an INFORMAT to a variable that is not being used to read from raw data.  It doesn't hurt, but why bother?

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

What is the purpose of the second data step?

data f;
  set ds1;
  visit_date=date ;
  informat date date10.;
  format date date10.;
run;

It looks like you are creating a new (and hence totally missing) variable and then using it to overwrite the variable VISIT_DATE that you read from the DS1 dataset.

Perhaps you meant to do this?

data f;
  set ds1;
  date = visit_date ;
  format date date9.;
run;

Not sure what value using a width of 10 does for the DATE format.  DATE9 will print with four digit years.  DATE11 will add hyphens around the month.

Also not sure what value is added by assigning an INFORMAT to a variable that is not being used to read from raw data.  It doesn't hurt, but why bother?

kmnagasree
Calcite | Level 5
thank you

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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