Smallest and largest value of concatenation (is8601dt )

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Smallest and largest value of concatenation (is8601dt )

Hai All,

  I’m having trouble with my SAS coding today, any kind of your generous help or small advice would be grateful for me.

  Here i have two char  Variables IMDT and IMST  .

  IMDT          IMST

20110113     1306

20110119     1530

20110224       .

20110314       .

1) How to get the smallest value concatenation of both IMDT and IMST in is8601dt format ?

2) How to get the  largest value of concatination of both IMDT and IMST in is8601dt format ?

Krishna


Accepted Solutions
Solution
‎09-23-2014 07:59 AM
Super User
Super User
Posts: 7,997

Re: Smallest and largest value of concatenation (is8601dt )

Posted in reply to KrishnaChandra

That is why I have the if statement in my code:

  if im_time=. then dt=input(strip(put(im_date,date9.))||":00:00:00",datetime.);

  else dt=input(strip(put(im_date,date9.))||":"||strip(put(im_time,tod5.))||":00",datetime.);

This means if time is missing the input date + 00:00:00 as datetime value otherwise use date and time.

Yes, it may have the variables mentioned but they are character -> right click on dataset and show columns, you will see they have a $xx for format.  These need to be converted into numeric dates/times so that they can be sorted.

What is the actual error you are getting with my code?

View solution in original post


All Replies
Trusted Advisor
Posts: 3,215

Re: Smallest and largest value of concatenation (is8601dt )

Posted in reply to KrishnaChandra

converting it to a datetime value? SAS(R) 9.4 Functions and CALL Routines: Reference, Third Edition (  DHMS(SAS date, 0, 0, SAS time).  )

A dt is a value in seconds since 1jan1960:0:0:0 you can do the calculation also yourself    min max of that should be no problem

---->-- ja karman --<-----
Super User
Super User
Posts: 7,997

Re: Smallest and largest value of concatenation (is8601dt )

Posted in reply to KrishnaChandra

You can use SQL or sort:

data have;
  imdt='13JAN2011'd; imst='13:06't; output;
  imdt='19JAN2011'd; imst='15:30't; output;
  imdt='22FEB2011'd; imst=.; output;
  imdt='14MAR2011'd; imst=.; output;
run;

proc sort data=have;
  by imdt imst;
run;

data want (keep=dt);
  set have end=last;
  attrib dt format=e8601dt.;
  if imst=. then dt=input(strip(put(imdt,date9.))||":00:00:00",datetime.);
  else dt=input(strip(put(imdt,date9.))||":"||strip(put(imst,tod5.))||":00",datetime.);
  if _n_=1 or last then output;
run;

Frequent Contributor
Posts: 89

Re: Smallest and largest value of concatenation (is8601dt )

Hai RW9

While i run with the code i can see some errors and only . is displayed on the dataset

NOTE: Invalid argument to function INPUT at line 829 column 8.

ERROR: Limit set by ERRORS= option reached.  Further errors of this type will not be printed.

last=0 INV=NIG INVSITE=08 PT=608008 CPEVENT=IMPLANT VISIT QUALV=01 SUB_EVE=0 DCMNAME=IMIN SUBSETSN=1 DCMSUBNM=IMIN1

DCMDATE=  REPEATSN=1 VISIT=80 ACTEVENT=80.00 IMINDT=20110119 IMINTM=1228 IMKTNO1=600040 IMINSP=1 IMININT=1 IMINOTX=

IMINAD=0 IMKTNO2=. IMKTNO3=. IMKTNO4=. IMKTNO5=. IMPLANT=1 IMINDOM=1 IMVOL=10 IMVOLU=cc IMINNOL=. IMINNOR=4 IMINNO=1

IMLEN1=5 IMLEN1U=mm IMLEN2=. IMLEN2U=mm IMLEN3=. IMLEN3U=mm IMPREV=1 IMSITE=2 IMPALP=4 IMINTRA=0 IMRETM=1235

IMPLAST=JENKIN STUDYID=Duotetramycin COUNTRY=NIG INVNAM=DR.Dre dt=. imst=. imdt=. _ERROR_=1 _N_=20

NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been

      set to missing values.

      Each place is given by: (Number of times) at (Line)Smiley SadColumn).

      94 at 829:8

NOTE: There were 94 observations read from the data set DS.SORTDS2.

NOTE: The data set DS.WANT has 2 observations and 1 variables.

NOTE: DATA statement used (Total process time):

      real time           0.09 seconds

      cpu time            0.03 seconds

Any way to solve this problem?

krishna

Super User
Super User
Posts: 7,997

Re: Smallest and largest value of concatenation (is8601dt )

Posted in reply to KrishnaChandra

I would suggest IMDT and IMST are not date or time variables but text.  Convert them to date/time respectively first:

data want;

     set have;

     im_date=mdy(input(substr(imdt,5,2),best.),input(substr(imdt,7,2),best.),input(substr(imdt,1,4),best.);

     if imst ne. then do;

          im_time=input(substr(imst,1,2)||":"||substr(imst,3,2),time5.);

     end;

run;

proc sort data=have;
  by im_date im_time;
run;

data want (keep=dt);
  set have end=last;
  attrib dt format=e8601dt.;
  if im_time=. then dt=input(strip(put(im_date,date9.))||":00:00:00",datetime.);
  else dt=input(strip(put(im_date,date9.))||":"||strip(put(im_time,tod5.))||":00",datetime.);
  if _n_=1 or last then output;
run;

Frequent Contributor
Posts: 89

Re: Smallest and largest value of concatenation (is8601dt )

Hai RW9

    I couldn't get the output.Really i have 4 dataset ,The dataset test contains 92 observations and it has the variables imdt and imst.I have merged all the 4 dataset and get a Target dataset.The Target dataset contains 170 observations ,then the "imst" has full null values after the 92th observation.My problem is to find the smallest value among imdt and imst after the concatenation

Solution
‎09-23-2014 07:59 AM
Super User
Super User
Posts: 7,997

Re: Smallest and largest value of concatenation (is8601dt )

Posted in reply to KrishnaChandra

That is why I have the if statement in my code:

  if im_time=. then dt=input(strip(put(im_date,date9.))||":00:00:00",datetime.);

  else dt=input(strip(put(im_date,date9.))||":"||strip(put(im_time,tod5.))||":00",datetime.);

This means if time is missing the input date + 00:00:00 as datetime value otherwise use date and time.

Yes, it may have the variables mentioned but they are character -> right click on dataset and show columns, you will see they have a $xx for format.  These need to be converted into numeric dates/times so that they can be sorted.

What is the actual error you are getting with my code?

Frequent Contributor
Posts: 89

Re: Smallest and largest value of concatenation (is8601dt )

I got the output thanks RW9.Smiley Happy

Contributor
Posts: 44

Re: Smallest and largest value of concatenation (is8601dt )

Posted in reply to KrishnaChandra

With Character dates and times you can use coalescec function to get rid off input errors. I just used RW9's code, you can make those char variables in datastep.

data have; 

imdt_c='13JAN2011'; imst_c='13:06';output; 

imdt_c='19JAN2011'; imst_c='15:30';output; 

imdt_c='22FEB2011'; imst_c='';output; 

imdt_c='14MAR2011'; imst_c='';output;

run;

proc sort data=have; 

by imdt imst;

run;

data want ; 

set have end=last; 

attrib dt format=e8601dt.; 

dt=input(imdt_c||":"||coalescec(imst_C,"00:00")||":00",datetime.);

run;

Frequent Contributor
Posts: 89

Re: Smallest and largest value of concatenation (is8601dt )

Posted in reply to AskoLötjönen

Hai

    Those imdt and imst contains around 92 observations.The value of imst is missing on some rows in real dataset Test.I merged the test dataset along with another three.The merged one has 170 observations but after 92th row the variable imst has no values till end.I can use so many code to solve this,unfortunately only got errors :smileyconfused: 

🔒 This topic is solved and locked.

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

Discussion stats
  • 9 replies
  • 454 views
  • 0 likes
  • 4 in conversation