DATA Step, Macro, Functions and more

SAS

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

SAS

I am trying to write down the beg_srvc_date between '01jan2016'd and '01jun2017'd; but I keep getting error in my run data. Please advice. Service from 01/01/2016 to service date 06/01/2017. 


Accepted Solutions
Solution
‎07-21-2017 12:10 PM
SAS Super FREQ
Posts: 3,755

Re: SAS

Let's use data that we all have access to. Is this what you are looking for? If not, please modify the DATA step:

 

data Subset;
set sashelp.snacks(rename=(Date=beg_srvc_date));
if '01jan2004'd < beg_srvc_date and beg_srvc_date < '01jun2004'd then do;
   /* do something here */
   foundDate = 1;
end;
else do;
   /* do something else here */
   foundDate = 0;
end;
run;

proc freq data=Subset;
tables foundDate;
run;

View solution in original post


All Replies
PROC Star
Posts: 767

Re: SAS

Please provide some of the code that you are using and preferably some sample data Smiley Happy

Occasional Contributor
Posts: 6

Re: SAS

and beg_srvc_date between "01jan2016"d and "01jun2017"d;

PROC Star
Posts: 7,492

Re: SAS

You can only use between in a where statement. If you are trying to use it in an IF statement try:

and  "01jan2016"d<=beg_srvc_date<="01jun2017"d;

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 6

Re: SAS

I have tried to eneter

and  "01jan2016"d<=beg_srvc_date<="01jun2017"d;

and it's still showing error. 

Super User
Super User
Posts: 7,994

Re: SAS

Post your code, some sample test data (in the form of a datastep), the log of that part etc.  It is pointless us trying to guess everything from the non information you have provided.  I mean does it run at all, is there errors/warnings, is beg_svc actually a date value or character?  Is it in the current query etc.  We need information to be able to tell you anything!

Occasional Contributor
Posts: 6

Re: SAS

and beg_srvc_date between "01jan2016"d and "01jun2017"d;
quit;

This is what I wrote and it is showing error message 

PROC Star
Posts: 767

Re: SAS

And what error message is printet in the log?

Occasional Contributor
Posts: 6

Re: SAS

Error: The following columns were not found in the contributing tables: beg_srvce_date;

and  "01jan2016"d<=beg_srvc_date<="01jun2017"d;

 

Super User
Super User
Posts: 7,994

Re: SAS

Thats because beg_srvce_date is not in the contributing dataset, nor is it actually shown in the tiny little code snippet you have provided.  Again, you need to provide all the information for us to be able to help you, we cannot see you machine, nor guess what you are doing.

PROC Star
Posts: 7,492

Re: SAS

Is it beg_srvce_date or beg_srvc_date?

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 11,343

Re: SAS


Izzy wrote:

and beg_srvc_date between "01jan2016"d and "01jun2017"d;
quit;

This is what I wrote and it is showing error message 


Post the code with error messages from the log. You are not providing sufficient information to answer your question without that detail.

Copy from your LOG, Open a code box on the forum using the menu icon {i} to preserve the format of the error message(s) otherwise the forum window may reformat the text moving critical indicators and paste into the code box.

Solution
‎07-21-2017 12:10 PM
SAS Super FREQ
Posts: 3,755

Re: SAS

Let's use data that we all have access to. Is this what you are looking for? If not, please modify the DATA step:

 

data Subset;
set sashelp.snacks(rename=(Date=beg_srvc_date));
if '01jan2004'd < beg_srvc_date and beg_srvc_date < '01jun2004'd then do;
   /* do something here */
   foundDate = 1;
end;
else do;
   /* do something else here */
   foundDate = 0;
end;
run;

proc freq data=Subset;
tables foundDate;
run;
Occasional Contributor
Posts: 6

Re: SAS

[ Edited ]

Thank you Rick and everyone else for their contribution. I will make the changes and adjustments to the data. 

☑ This topic is solved.

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

Discussion stats
  • 13 replies
  • 267 views
  • 2 likes
  • 6 in conversation