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;
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.
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
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.
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.
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
data _null_;
set QueryRules end=eof;
by Rule_Order;
put analysis_desc rule rule_order;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.