DATA Step, Macro, Functions and more

base sas

Accepted Solution Solved
Reply
Highlighted
New Contributor
Posts: 2
Accepted Solution

base sas

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.

Accepted Solutions
Solution
a week ago
Super User
Super User
Posts: 8,125

Re: base sas

[ Edited ]
Posted in reply to kmnagasree

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


All Replies
Solution
a week ago
Super User
Super User
Posts: 8,125

Re: base sas

[ Edited ]
Posted in reply to kmnagasree

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?

New Contributor
Posts: 2

Re: base sas

thank you
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 66 views
  • 0 likes
  • 2 in conversation