BookmarkSubscribeRSS Feed
Reeza
Super User

So its a number, not a character date. Change the formulas as below in all the relevant places.

input(put(a.regis_dt, 8. -l), mmddyy10.)

pasvorto
Calcite | Level 5

Current code:

proc sql;

CREATE table ccases1a

   as SELECT

        a.study AS study_num,  i.inst_id,  a.patient AS patient_id, a.regis_dt, a.pt_sex AS sex_id, a.ethnicity AS ethnic_id

      FROM calgb.rss_accrual as a

   JOIN calgb.institution as i

      ON a.inst_nci_id = i.nci_id

        WHERE i.GROUP_ID = 1

           and input(put(a.regis_dt, 8. -l), mmddyy10.) >= &start.

           AND (input(put(i.stop_dt, 8. -l), mmddyy10.) =. or input(put(a.regis_dt, 8. -l), mmddyy10.) <= &end.);

quit;

current error:

ERROR: Numeric format F in PUT function requires a numeric argument.

ERROR: Numeric format F in PUT function requires a numeric argument.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE SQL used (Total process time):

      real time           0:00.01

      cpu time            0:00.01

Reeza
Super User

this means that stop_dt and regis_dt don't have the same formats.  Clarify this. If it is a number use the one above, if its a character use the first one.

pasvorto
Calcite | Level 5

They are character fields. Here is what we have now.

24595   proc sql;

24596   CREATE table ccases1a

24597     as SELECT

24598          a.study AS study_num,  i.inst_id,  a.patient AS patient_id, a.regis_dt, a.pt_sex AS sex_id,

24598! a.ethnicity AS ethnic_id

24599        FROM calgb.rss_accrual as a

24600     JOIN calgb.institution as i

24601        ON a.inst_nci_id = i.nci_id

24602          WHERE i.GROUP_ID = 1

24606             AND input(a.regis_dt, yymmdd10.) >= &start.

24607             AND (input(i.stop_dt, yymmdd10.) =. or input(a.regis_dt, yymmdd10.) <= &end.);

ERROR: INPUT function requires a character argument.

ERROR: Expression using equals (=) has components that are of different data types.

24608   quit;

Is that the code you are referring to for character strings?

pasvorto
Calcite | Level 5

The second error had to do with the "=.". I changed that to = '' " and we're ok then.

Interestingly enough, this code works (in a data block).

where &start. <= input(regis_dt, yymmdd10.) <= &end.;

May the fact that it is contained in the sql code that is causing the problem.

pasvorto
Calcite | Level 5

I got around it by doing this, which does not give me any errors:

proc sql;

CREATE table ccases1a

   as SELECT

        a.study AS study_num,  i.stop_dt, i.inst_id,  a.patient AS patient_id, a.regis_dt, a.pt_sex AS sex_id, a.ethnicity AS ethnic_id

      FROM calgb.rss_accrual as a

   JOIN calgb.institution as i

      ON a.inst_nci_id = i.nci_id

        WHERE i.GROUP_ID = 1 ;

quit;

data ccases1a; set ccases1a;

   where   input(regis_dt, yymmdd10.) >= &start.

           AND (stop_dt =. or input(regis_dt, yymmdd10.) <= &end.);

run;

Reeza
Super User

So basically, stop_dt is a valid SAS date and regis_dt is a character field already.

Glad you got it working.

pasvorto
Calcite | Level 5

I have to check the data but stop_dt is missing in the output. I have to see if it existed in the input.

Thanks for all your help. It appears that pulling the test out of the SQL made it all work.

Tom
Super User Tom
Super User

Your problem seems to be that you do not know what format you dataset variables are in.  Use PROC CONTENTS and check. If they are numbers with a format like DATE, MMDDYY, YYMMDD, etc attached to them then they are DATES and you can compare them with a macro variable by setting the macro variable in DATE9 format and using it in a date literal.

%let start=01MAR2013 ;

....  a.regis_dt > "&start"d

If your macro variable START is in some other format then you can use the INPUT (or INPUTN) function to convert it to an actual date. There is no need to format it as you will be comparing the number and not the way the number is displayed.

%let start=2013-03-01 ;

... a.regis_dt > input("&start",yymmdd10.)

If your dataset variables are NOT dates then you can apply functions to them also to convert.  For example if instead they are DATETIME values then use the DATEPART() function to convert them to date values. If they are character strings then use the INPUT function to convert them to dates.

%let start=01MAR2013 ;

....  input(a.regis_dt,yymmdd10.) > "&start"d

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 23 replies
  • 3691 views
  • 0 likes
  • 7 in conversation