Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-09-2016 11:25 AM
(655 views)

Hello,

I got a problem with set defining since I am a beginner and I appreciate if somebody helps me here.

I have a data set as below

Rank | Person1 | Next_person | Money |

1 | A | B | 100 |

1 | A | B | 120 |

2 | A | B | 120 |

1 | B | C | 110 |

1 | B | C | 120 |

2 | B | C | 120 |

I am skiping rest of the table here.

First column is rank of the person, second column is the person and the third column is the person next to person1. The last column shows the money person1 s. I already define this set in my optmodel:

set<num, str, num> rank_per_mny;

rank_per_mny = [Rank Person1 Money]

Then I need to have kind of a product of this set with itself to give me a set as :

{Rank,Person1,Money(for person1),Money(for Next_person)}

Basically, I want to add the next_person money to the previous set (for the same rank) and I think it is a product between this set and itself. For this example the set I need will be this:

{1,A,100,110}, {1,A,100,120}, , {1,A,120,110}, , {1,A,100,120}, , {2,A,120,120},

I wrote the followingcode but I it does not get the correct values. Like it should start the Money for next_person from 110 but it starts from 100 again. I appreciate your help.

proc optmodel;

set<num, str, num> rank_per_mny;

rank_per_mny = [Rank Person1 Money];

set<num, str,str, num> rank_per_mny_mny;

rank_per_mny_mny = [Rank Person1 Next_person Money];

set< number> money;

set< num, str, num > assign;

set< num, str, num,number> cross;

for {< Rank, Person1, Next_person, Money > in rank_per_mny_mny }

money = setof{< Rank Next_person Money > in rank_per_mny } Money ;

assign = setof{< Rank Person1 Money > in rank_per_mny }{<Rank Person1 Money>;

cross = cross union (assign cross price);

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
data data1;
input person $ next $;
datalines;
A B
B C
;
data data2;
input Rank Person1 $ Money;
datalines;
1 A 100
1 A 120
2 A 120
1 B 110
1 B 120
2 B 120
;
proc optmodel;
set <str> PEOPLE;
str next {PEOPLE};
read data data1 into PEOPLE=[person] next;
set<num, str, num> rank_per_mny;
read data data2 into rank_per_mny = [Rank Person1 Money];
put (setof {<r,p,m> in rank_per_mny, <(r),next[p],m2> in rank_per_mny} <r,p,m,m2>)=;
quit;
```

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
data data1;
input person $ next $;
datalines;
A B
B C
;
data data2;
input Rank Person1 $ Money;
datalines;
1 A 100
1 A 120
2 A 120
1 B 110
1 B 120
2 B 120
;
proc optmodel;
set <str> PEOPLE;
str next {PEOPLE};
read data data1 into PEOPLE=[person] next;
set<num, str, num> rank_per_mny;
read data data2 into rank_per_mny = [Rank Person1 Money];
put (setof {<r,p,m> in rank_per_mny, <(r),next[p],m2> in rank_per_mny} <r,p,m,m2>)=;
quit;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

yes

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Ok I got the idea. Thanks, It was very helpful!

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.