- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
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]
- 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
- 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