Help using Base SAS procedures

Array concept

Super Contributor
Posts: 1,041

Array concept


I i want to use array to scan cach observation and do a particular calculation if the condition is met...

The condition is that if the data is more than 3 decimals(2 decimals rather)  i want to do the calculation 60*60*24

data is like :

10.75   0.41875     19:40   CU-O

When it scans this record only 0.41875 gets the calculation done

19:40 is in the time format(not decimal so no calculation done))

CU-O is some charecter data

Lastly after it does the calculation only those need to be converted into time4. format???


Respected Advisor
Posts: 3,852

Re: Array concept

Posted in reply to robertrao

What is the data type of these variables.

Also give more sample data and the code to read it.

Valued Guide
Posts: 653

Re: Array concept

Posted in reply to robertrao

That you want to multiply implies numeric values, however 19:40 is not a numeric value (unless we are seeing the formatted value).  This suggests that the incoming values are character and that you want to parse them and convert them to numeric.   As DATA _NULL_ said show us what you hope to see as an outcome and especially pay attention to the numeric / character issue.

Valued Guide
Posts: 653

Re: Array concept

Posted in reply to robertrao

OK it sounded like fun so.  Assuming that all are character and they are to be converted to numeric.  Try this:

data have;

length val1-val4 $8;

input val1 val2 val3 val4;


0.75   0.41875     19:40   CU-O

0.75   0.41875     19:40   CU-O

1.0    2.22        3.333   xxxx

5      199         12.1212 yyyy


data want;

   set have;

   array values {3} $ val1-val3;

   array nums   {3} num1 - num3;

   do i = 1 to dim(values);

      if index(values{i},':') then nums{i}=input(values{i},hhmmss.);

      else if length(scan(values{i},2))>2 then nums{i}=input(values{i},best.)*60*60*24;

      else nums{i}=input(values{i},best.);



Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation