BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8


Hi,

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???

Regards

3 REPLIES 3
data_null__
Jade | Level 19

What is the data type of these variables.

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

ArtC
Rhodochrosite | Level 12

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.

ArtC
Rhodochrosite | Level 12

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;

datalines;

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

run;

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.);

   end;

   run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 809 views
  • 0 likes
  • 3 in conversation