BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gsnidow
Obsidian | Level 7

Greetings.  I'm trying to create a dataset in work from another dataset where a date in the source table is greater than or equeal to an input parameter, and less than or equal to another input parameter.  I've tried putting it in quotes, using a period after them, and then both of those, and neither of these, and I can't get it to work.  I worked on a macro this week where the only way I could get a variable to resolve was to put double quotes around it.  And it seems sometimes I need to put a period after a variable and sometimes not.  I'm haveing a terrible time trying to find a general rule of thumb for using variables.  This is what I am trying, and I sure would appreciate any tips.  Thank you.

%Let dt_start = 2012-09-01;

%Let dt_end = 2012-09-30;

data work.new_recs;

set main.otbr_master;

if dt_bill >= &dt_start.;

  if dt_bill <= &dt_stop.;

run;quit;

This is the error...

1817  %Let dt_start = 2012-09-01;
1818  %Let dt_end = 2012-09-30;
1819  data work.new_recs;
1820      set main.otbr_master;
1821      if dt_bill >= &dt_start.;
1822          if dt_bill <= &dt_stop.;
                            -
                            390
                            200
WARNING: Apparent symbolic reference DT_STOP not resolved.
ERROR 390-185: Expecting an relational or arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

1823  run;

1 ACCEPTED SOLUTION

Accepted Solutions
shivas
Pyrite | Level 9

Hi,

if dt_bill <= &dt_end.;


Thanks,

Shiva

View solution in original post

8 REPLIES 8
shivas
Pyrite | Level 9

Hi,

if dt_bill <= &dt_end.;


Thanks,

Shiva

gsnidow
Obsidian | Level 7

DOH!!!  Oh my goodness I need to teak a break from this.  How could I have missed that?  Thank you.

gsnidow
Obsidian | Level 7

Well now I've got another problem with this.  The variable dt_bill is a 10 character text field.  Is there any way I can change it to mm/dd/yyyy date format?  Thanks.

Greg

shivas
Pyrite | Level 9

Hi,

data want;

  char_date = '01/10/2011' ;

  num_date = input(char_date, mmddyy10.);

  format num_date mmddyy10.;

run;

Thanks,

Shiva

Tom
Super User Tom
Super User

If you are going to store dates in character variables it is best to use YYYY/MM/DD format so that the character strings will sort in chronological order.

gsnidow
Obsidian | Level 7

Tom, the only reason it is in text format is because that is how it is stored on the mainframe.  This goes back to something you helped me with last week.  If i'm pulling in data from a mainframe file like so...

FILENAME ezt "PPPCTK.ZZZ.BALANCED.REVXREC.DSKO745(-&i)" DISP=SHR;

data work.ontime&i;

INFILE ezt;

input

@1   ID_BA      PD6.

@7  CD_BUS    $4.

@16  DT_BILL    $10.   <<<---- I need this to end up as a date in the dataset.

@48  AT_SVC_UNIT_BILLED PD6.2

@100 CD_RATE    $3.

@138 CD_REV_SRC   $2.

@154 CD_CYCLE   IB2.

@201 FL_MORE_REV_REC  $1.;

run;

How can I make the field 'dt_bill' be in date format.  I am eventually putting this data into Excel, and '2012-09-01' does not convert to a date format in Excel, so I need it to be in a format like '9/1/2012', or anything Excel will recognize as a date.  Thank you.

gsnidow
Obsidian | Level 7

I think this will work...

data test;
input dt_bill $10.;
cards;
2012-09-01
2012-09-02
2012-09-03
;
run;

data test;
set test;
bill_dt = input(dt_bill,yymmdd10.);
format bill_dt mmddyy10.;
run;

Tom
Super User Tom
Super User

You could change the input format in the step that is reading the text file so that it reads it as a date instead of a character string.

... @16  DT_BILL    mmddyy10.

...

I have to trouble with excel automatically reading YYYY-MM-DD or YYYY/MM/DD strings as dates.

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
  • 8 replies
  • 2920 views
  • 0 likes
  • 3 in conversation