BookmarkSubscribeRSS Feed
buechler66
Barite | Level 11

Hi. I'm interested in taking the 3 variables from my QueryRules dataset and creating an array that I can iterate thru array record and assign each of the 3 values to 3 different variables as SAS iterates thru each record in my final QueryRules dataset.

 

Would it be best to create 3 different arrays or 1 array containing 3 variables? Can anyone help me with the syntax to build this type of SAS object?  I'd really appreciate some help here.

 

data QueryRules;
infile cards dsd dlm='|' truncover ;
informat analysis_desc $34. rule $64.;
input analysis_desc $ rule $ rule_order;
(BUILD ARRAY HERE???) cards; ACTUAL DELIVERY DATE MISSING IN IV|A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL|1 ACTUAL DELIVERY DATE LATER IN IV|A.ACTUAL_DLVRY_DATE > B.ACTUAL_DLVRY_DATE|1.5 run;

 

data _null_;
 set QueryRules end=eof;
 by Rule_Order;
 file '/home/ssbuechl/myfile.txt';
 the_analysis_desc= (somehow reference an array here to assign each array value) ;
 the_rule= (somehow reference an array here to assign each array value) ;
 the_rule_order= (somehow reference an array here to assign each array value) ;
 put the_rule the_rule_order;
 run;
6 REPLIES 6
Reeza
Super User

Please post sample data regarding input and desired output.

 

PS. As someone mentioned before, whatever process you're working on regarding rules seems very very cumbersome.

buechler66
Barite | Level 11

Ok, here's my sample data and I think I have an array working, but the Put statement is actually putting out all 3 columns of the array. I don't seem to have control over individual columns.

 

rsubmit;

data QueryRules;
infile cards dsd dlm='|' truncover ;
informat analysis_desc $34. rule $64.;
input analysis_desc $ rule $ rule_order $;
cards;
ACTUAL DELIVERY DATE MISSING IN IV|A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL|1
ACTUAL DELIVERY DATE LATER IN IV|A.ACTUAL_DLVRY_DATE > B.ACTUAL_DLVRY_DATE|1.5
run;

data _null_;
 set QueryRules end=eof;
 by Rule_Order;
 file '/home/ssbuechl/myfile.txt';
 array qr_array {3} $ 36 analysis_desc rule rule_order;
 do i = 1 to dim(qr_array);
  analysis_desc=qr_array{i};
  put analysis_desc;
 end;

 run;

 endrsubmit;

 

It's outputing:

ACTUAL DELIVERY DATE MISSING IN IV
A.ACTUAL_DLVRY_DATE IS NULL AND B.
1
ACTUAL DELIVERY DATE LATER IN IV
A.ACTUAL_DLVRY_DATE > B.ACTUAL_DLV
1.5

My desired output in this case would be:

ACTUAL DELIVERY DATE MISSING IN IV
ACTUAL DELIVERY DATE LATER IN IV

 

Reeza
Super User

if i=1 then put ...

 

I'm not sure what you're expecting from the array.

If you only want to put one variable why create the array in the first place.

ballardw
Super User
do i = 1 to dim(qr_array);
  analysis_desc=qr_array{i};
  put analysis_desc;
 end;

The Do loop says to put each variable in the array on a separate line AND loses the original value of analysid_desc because you overwrite it.

 

If you only want tp put out the first then either 1) skip the loop and array and say Put analysis_desc;

Or only loop once and use

 

Put qr_array[i];

 

And you have yet to show what your actual final desired output is.

buechler66
Barite | Level 11

Got it!  Is there a better way to do what I'm doing below?

 

rsubmit;

data QueryRules;
infile cards dsd dlm='|' truncover ;
informat analysis_desc $34. rule $64.;
input analysis_desc $ rule $ rule_order $;
cards;
ACTUAL DELIVERY DATE MISSING IN IV|A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL|1
ACTUAL DELIVERY DATE LATER IN IV|A.ACTUAL_DLVRY_DATE > B.ACTUAL_DLVRY_DATE|1.5
run;



data _null_;
 set QueryRules end=eof;
 by Rule_Order;
 file '/home/ssbuechl/myfile.txt';

/*Explicit, Nested*/
array analysis_desc_array {1} $ 35 analysis_desc;
array rule_array {1} $ 65 rule;
array rule_order_array {1} $ 5 rule_order;
do i = 1 to dim(analysis_desc_array);
	do j = 1 to dim(rule_array);
		do k = 1 to dim(rule_order_array);
			analysis_desc=analysis_desc_array{i};
			rule=rule_array{j};
			rule_order=rule_order_array{k};
			put analysis_desc rule rule_order;
		end;
	end;
end;

run;

endrsubmit;
ACTUAL DELIVERY DATE MISSING IN IV A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL 1
ACTUAL DELIVERY DATE LATER IN IV A.ACTUAL_DLVRY_DATE > B.ACTUAL_DLVRY_DATE 1.5

 

Reeza
Super User

data _null_;
set QueryRules end=eof;
by Rule_Order;


put analysis_desc rule rule_order;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 900 views
  • 3 likes
  • 3 in conversation