DATA Step, Macro, Functions and more

How to use datepart and format in date9.

Accepted Solution Solved
Reply
Senior User
Posts: 1
Accepted Solution

How to use datepart and format in date9.

I've been using this data step to try and get the date from a datetime format (SELLSTARTDATE):

 

data sorted_table (keep= productid color SELLSTARTDATE);
set sorted;
SELLSTART=datepart(SELLSTARTDATE);
format SELLSTART date9.;
run;

 

It does not create a SELLSTART column or format it in date9.

 

Thanks


Accepted Solutions
Solution
‎01-30-2018 07:04 AM
Super User
Posts: 6,543

Re: How to use datepart and format in date9.

Posted in reply to graham114

You put KEEP= in the wrong place.  It belongs on the SET statement:

 

data sorted_table;
set sorted (keep=product color SELLSTARTDATE);

 

While KEEP= can be used in either place, it belongs on the SET statement for this particular DATA step.  On the DATA statement, it limits the variables that become part of the new data set.

View solution in original post


All Replies
Super User
Super User
Posts: 9,227

Re: How to use datepart and format in date9.

Posted in reply to graham114

On your keep= line you do not specify to keep sellstart, hence its not in the output dataset.  Also avoid coding in captials it really makes reading code harder.

Solution
‎01-30-2018 07:04 AM
Super User
Posts: 6,543

Re: How to use datepart and format in date9.

Posted in reply to graham114

You put KEEP= in the wrong place.  It belongs on the SET statement:

 

data sorted_table;
set sorted (keep=product color SELLSTARTDATE);

 

While KEEP= can be used in either place, it belongs on the SET statement for this particular DATA step.  On the DATA statement, it limits the variables that become part of the new data set.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 109 views
  • 2 likes
  • 3 in conversation