Hi,
i wanted to solve a problem but i am little bit confuse as i am learning SAS.
Here is the algorithm of my code
data operation;
set rule_data;
if satisfy condition then
do;
set data_value ;
if match_condition_of_rule_data_with_data_value then;
peform opeartion on data_value based on rule_data;
end;
run;
when i am trying this,it gives me combine data set and not giving result as i expected as i want value from rule_data_set only and both dataset have different number of observations and variables.
You might want to use a merge instead, it is not possible (at least in an easy fashion) to have multiple datasets open at the samt time in a data step.
data operation;
merge rule_data data_value ;
by common_key;
if match_condition_of_rule_data_with_data_value then;
peform opeartion on data_value based on rule_data;
end;
run;
//Fredrik
Hi FredrikE,,
As i mentioned both data set have different number of observations and variables. suppose rule_data has only 50 observations and data_value has 2 millions observation. how is it possible to merge in such condition ? and even if it merged somehow then second challenge i have to apply observation of rule_data on data_value so i need to iterate 50 times on 2 millions data but if i merge it will iterate 2 millions times it is very confusing for me to understand.
First off, if your learning SAS this is not the the topic to start with, nor is that amount of data. Both are for more advanced users. If you make it harder to learn you will more likely fail.
Secondly, with that kind of data, yes, merge probably isn't the way forward. Working with big data is slightly different, hence why you should learn Base SAS thoroughly before moving onto more advanced topics.
As I posted, you can generate the necessary code:
data _null_; set rule_data end=last;
if _n_=1 then call execute('data want; set have;'); call execute(rule);
if last then call execute('run;'); run;
However it is highly unlikely you will understand what is being done here if you are learning SAS. What this will do is create a datastep statement after this one has finished, which has the rule statement for each observation from rule table. That generated code is then run.
There are numerous ways to do this, generate the code from the rule dataset is one that jumps to mind, merging another . So something like:
data _null_; set rule_data; call execute(...); run;
Note I can't provide working code as you have shown no test data in the form of a datastep.
Well, we're making assumptions based on the pseudocode you provided, but it would be better to actually provide sample data and code that we can work off and see more easily what you want.
My first instinct is to say that what you're doing isn't possible...at least easily...but there are ways. It would be better if you first explained in detail what you want.
@ramanandyadav wrote:
Hi,
i wanted to solve a problem but i am little bit confuse as i am learning SAS.
Here is the algorithm of my code
data operation;
set rule_data;
if satisfy condition then
do;
set data_value ;if match_condition_of_rule_data_with_data_value then;
peform opeartion on data_value based on rule_data;
end;
run;
when i am trying this,it gives me combine data set and not giving result as i expected as i want value from rule_data_set only and both dataset have different number of observations and variables.
As the other contributors have said a merge may be your best bet - alternatively an SQL join might also be able to do what you what which you may find easier if you come from an SQL background.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.