BookmarkSubscribeRSS Feed
ramanandyadav
Fluorite | Level 6

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.

6 REPLIES 6
FredrikE
Rhodochrosite | Level 12

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

ramanandyadav
Fluorite | Level 6

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Reeza
Super User

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.


 

ChrisBrooks
Ammonite | Level 13

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

SAS Enterprise Guide vs. SAS Studio

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.

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
  • 1059 views
  • 4 likes
  • 5 in conversation