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;
Hi,
if dt_bill <= &dt_end.;
Thanks,
Shiva
DOH!!! Oh my goodness I need to teak a break from this. How could I have missed that? Thank you.
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
Hi,
data want;
char_date = '01/10/2011' ;
num_date = input(char_date, mmddyy10.);
format num_date mmddyy10.;
run;
Thanks,
Shiva
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.
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.
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;
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.