DATA Step, Macro, Functions and more

character to numeric with sas time formats using array

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 142
Accepted Solution

character to numeric with sas time formats using array

[ Edited ]

Hi!

 

I need some help trouble shooting this syntax.  Trying to change all my character strings for time varialbes into formated sas time variables.  I'm getting error 'Illegal Regerence to the array _num'.

 

Here is my syntax

data med.time2006;
set med.time2006 (keep=TranAlert TranLaunch TranOnScene TranRecov TranDeliv GCSTime 
		VitalTime1 VitalTime2 VitalTime3 VitalTime4 VitalTime5 VitalTime6
		MedGiveTime1 MedGiveTime2 MedGiveTime3 MedGiveTime4 MedGiveTime5 MedGiveTime6 MedGiveTime7 
		IV1Time IV2Time PainScaleTime1 PainScaleTime2 PainScaleTime3 PainScaleTime4 PainScaleTime5 PainScaleTime6
rename=(tranalert=tranalert_a TranLaunch=tranlaunch_a TranOnScene=tranonscene_a TranRecov=tranrecov_a 
		TranDeliv=trandeliv_a GCSTime=gcstime_a VitalTime1=vitaltime1_a VitalTime2=vitaltime2_a VitalTime3=vitaltime3_a VitalTime4=vitaltime4_a 
		VitalTime5=vitaltime5_a VitalTime6=vitaltime6_a MedGiveTime1=medgivetime1_a MedGiveTime2=medgivetime2_a MedGiveTime3=medgivetime3_a 
		MedGiveTime4=medgivetime4_a MedGiveTime5=medgivetime5_a MedGiveTime6=medgivetime6_a MedGiveTime7=medgivetime7_a  
		IV1Time=IVTime_a IV2Time=IVTime2_a PainScaleTime1=painscaletime1_a PainScaleTime2=painscaletime2_a PainScaleTime3=painscaletime3_a 
		PainScaleTime4=painscaletime4_a  PainScaleTime5=painscaletime5_a PainScaleTime6=painscaletime6_a ));

array _char (*) $ TranAlert_a TranLaunch_a TranOnScen_a TranReco_a TranDeliv_a GCSTime_a 
		VitalTime1_a VitalTime2_a VitalTime3_a VitalTime4_a VitalTime5_a VitalTime6_a
		MedGiveTime1_a MedGiveTime2_a MedGiveTime3_a MedGiveTime4_a MedGiveTime5_a MedGiveTime6_a MedGiveTime7_a 
		IV1Time_a IV2Time_a PainScaleTime1_a PainScaleTime2_a PainScaleTime3_a PainScaleTime4_a PainScaleTime5_a PainScaleTime6_a;
array _num (*)  TranAlert TranLaunch TranOnScene TranRecov TranDeliv GCSTime 
		VitalTime1 VitalTime2 VitalTime3 VitalTime4 VitalTime5 VitalTime6
		MedGiveTime1 MedGiveTime2 MedGiveTime3 MedGiveTime4 MedGiveTime5 MedGiveTime6 MedGiveTime7 
		IV1Time IV2Time PainScaleTime1 PainScaleTime2 PainScaleTime3 PainScaleTime4 PainScaleTime5 PainScaleTime6;
do i=1 to dim(_char);
		_num=input(_char(i),best12.);
		_num=hms(floor(_num/100),mod(_num,100),0);
		format _num time12.;
		end;
run;

Help is appreciated!


Accepted Solutions
Solution
‎08-08-2017 01:50 PM
Trusted Advisor
Posts: 1,918

Re: character to numeric with sas time formats using array

Try replacing all appearances of _num with _num(i), and in the format statement, use the actual variable names instead of the array name _num;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,918

Re: character to numeric with sas time formats using array

I'll let you do the counting. You need to have the exact same number of variables in _char and _num. Do you?

Frequent Contributor
Posts: 142

Re: character to numeric with sas time formats using array

Posted in reply to PaigeMiller
@PaigeMiller Yes, I double counted...27
Solution
‎08-08-2017 01:50 PM
Trusted Advisor
Posts: 1,918

Re: character to numeric with sas time formats using array

Try replacing all appearances of _num with _num(i), and in the format statement, use the actual variable names instead of the array name _num;

Frequent Contributor
Posts: 142

Re: character to numeric with sas time formats using array

Posted in reply to PaigeMiller

@PaigeMiller It worked!  Thank you so much!

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 71 views
  • 0 likes
  • 2 in conversation