Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Need help with combinations

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**.
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 03-21-2023 12:27 PM
(497 views)

Hi,

I have a table in SAS that looks like this:

Then I want the have one value for each column like this:

permutation | first_stat | second_stat | third_stat |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

6721 | Multishot | Critical Chance | Critical Damage |

Anyone know how to do this with code?

1 ACCEPTED SOLUTION

Accepted Solutions

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

Here is one way to provide example data as a data step. I'm using delimited with , because I have no idea what you actually have but the comma helps with some issues around reading the spaces embedded in string values.

data example; infile datalines dlm=','; informat permutation f8. first_stat second_stat third_stat $15.; input permutation first_stat second_stat third_stat ; datalines; 6721,Multishot,Critical Chance,Critical Damage 6721,Critical Chance,Multishot,Critical Damage 6721,Critical Damage,Multishot,Critical Chance 6721,Critical Damage,Critical Chance,Multishot ;

If the request is actually to re-order the values then perhaps:

data want; set example; call sortc(third_stat, second_stat, first_stat); run;

The Call Sortc function sorts the variables shown so that the result will have the lowest sort order value in the first parameter, the second lowest in the second and so on. The order you showed implies that you want the first_stat to have the highest sort value (M comes after C) and it happens that "Damage" would come after "Chance" so that determined the order of the variables in the call.

Is this related to a role-playing game by any chance?

[Admin - Added documentation link to SORTC Function]

5 REPLIES 5

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

Can you reword your request, as I do not understand how you are going from your input "have" data to your output "want" data

If this helps:

- What are the rules that you are applying
- Why does your "want" data have multiple identical rows
- What have you tried? Provide sample data, code and the log

Basically the more information you provide in as simple form as possible the greater the chance you will get a helpful response.

Here's an example (not related to this post)

```
/* Create sample "have" data */
data have ;
format
date1 date.
date2 date.
;
do i=1 to 10 ;
date1 =today()+int(ranuni(1)*30) ;
date2 =today()+int(ranuni(2)*30) ;
output have ;
end ;
run ;
/* What I tried */
proc sql ;
create table want as
select intck('day',date1, date2) as c_los
from have
where c_los< 10 ;
;
quit ;
run ;
```

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

We can't work with data in screen captures. You will need to provide a portion of your data as working SAS data step code (instructions), and not in any other format.

--

Paige Miller

Paige Miller

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

Here is one way to provide example data as a data step. I'm using delimited with , because I have no idea what you actually have but the comma helps with some issues around reading the spaces embedded in string values.

data example; infile datalines dlm=','; informat permutation f8. first_stat second_stat third_stat $15.; input permutation first_stat second_stat third_stat ; datalines; 6721,Multishot,Critical Chance,Critical Damage 6721,Critical Chance,Multishot,Critical Damage 6721,Critical Damage,Multishot,Critical Chance 6721,Critical Damage,Critical Chance,Multishot ;

If the request is actually to re-order the values then perhaps:

data want; set example; call sortc(third_stat, second_stat, first_stat); run;

The Call Sortc function sorts the variables shown so that the result will have the lowest sort order value in the first parameter, the second lowest in the second and so on. The order you showed implies that you want the first_stat to have the highest sort value (M comes after C) and it happens that "Damage" would come after "Chance" so that determined the order of the variables in the call.

Is this related to a role-playing game by any chance?

[Admin - Added documentation link to SORTC Function]

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

That is a very good solution

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

Yes it's related to a game

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 16. Read more here about **why** you should contribute and **what is in it** for you!

How to Concatenate Values

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.