DATA Step, Macro, Functions and more

Variables not resolving

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 124
Accepted Solution

Variables not resolving

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;


Accepted Solutions
Solution
‎09-19-2012 12:20 PM
Super Contributor
Posts: 349

Re: Variables not resolving

Hi,

if dt_bill <= &dt_end.;


Thanks,

Shiva

View solution in original post


All Replies
Solution
‎09-19-2012 12:20 PM
Super Contributor
Posts: 349

Re: Variables not resolving

Hi,

if dt_bill <= &dt_end.;


Thanks,

Shiva

Frequent Contributor
Posts: 124

Re: Variables not resolving

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

Frequent Contributor
Posts: 124

Re: Variables not resolving

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

Super Contributor
Posts: 349

Re: Variables not resolving

Hi,

data want;

  char_date = '01/10/2011' ;

  num_date = input(char_date, mmddyy10.);

  format num_date mmddyy10.;

run;

Thanks,

Shiva

Super User
Super User
Posts: 7,038

Re: Variables not resolving

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.

Frequent Contributor
Posts: 124

Re: Variables not resolving

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.

Frequent Contributor
Posts: 124

Re: Variables not resolving

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;

Super User
Super User
Posts: 7,038

Re: Variables not resolving

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.

🔒 This topic is solved and locked.

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

Discussion stats
  • 8 replies
  • 1020 views
  • 0 likes
  • 3 in conversation