BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rsathe
Calcite | Level 5

 

Hi SAS Community,

 

     i have data set and i want to split three variable and run nested loop of three and generate new data set. i am from java background so it is very difficult for me to do this. please can you help to provide hint or solution.

 

Below is Required Data set

 

data company_data;
infile datalines dsd;
input $warehouse factory $ store $ product $ address $;
datalines;
"11,22","24,27","12,23","ABC"
"1,2,3","6,7","3,2","CDE"
"72,73","10,20,30,24","4,5,6,7","IJK"
;

company.PNG

 

 

Required Result

result.PNG

 

i wan to generate all possible combination of factory, store and product and i have tried but it is not useful show code here because it is not working properly.

 

Thank You,

  

 

1 ACCEPTED SOLUTION

Accepted Solutions
FredrikE
Rhodochrosite | Level 12

Three nested it is 🙂

 

data out;
  set company_data;
  length fac sto pro $3;


  i1 = 1;
  fac = scan(factory,i1);

 

  do while (fac ne '');
    i2 = 1;
    sto = scan(store,i2);

    do while (sto ne '');
      i3 = 1;
      pro = scan(product,i3);

      do while (pro ne ''); 
        output;
        i3 + 1;
        pro = scan(product,i3);
      end;

      i2 + 1;
    sto = scan(store,i2);
    end;

    i1 + 1;
    fac = scan(factory,i1);
  end;
run;

 

 

//Fredrik

View solution in original post

1 REPLY 1
FredrikE
Rhodochrosite | Level 12

Three nested it is 🙂

 

data out;
  set company_data;
  length fac sto pro $3;


  i1 = 1;
  fac = scan(factory,i1);

 

  do while (fac ne '');
    i2 = 1;
    sto = scan(store,i2);

    do while (sto ne '');
      i3 = 1;
      pro = scan(product,i3);

      do while (pro ne ''); 
        output;
        i3 + 1;
        pro = scan(product,i3);
      end;

      i2 + 1;
    sto = scan(store,i2);
    end;

    i1 + 1;
    fac = scan(factory,i1);
  end;
run;

 

 

//Fredrik

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
  • 1 reply
  • 777 views
  • 2 likes
  • 2 in conversation