How to record qualitative variable with over 100 dummies to several levels as quantitative in SAS
up vote
-1
down vote
favorite
I am working with SAS and want to record variable which with over 50+ different qualitative dummies. For example, the state of the U.S.
In this case, I just want to reduce them into 4 or 5 levels dummy as quantitative variable.
I get several ideaS, for example to use if/else statement, however, the problem is that i have to write down and specify each of area name in SAS and the code looks like super heavy.
Is there any other ways to do that without redundant code? Or to avoid write each specific name of variable? In SAS.
Any ideas are appreciated!!
sas statistics
add a comment |
up vote
-1
down vote
favorite
I am working with SAS and want to record variable which with over 50+ different qualitative dummies. For example, the state of the U.S.
In this case, I just want to reduce them into 4 or 5 levels dummy as quantitative variable.
I get several ideaS, for example to use if/else statement, however, the problem is that i have to write down and specify each of area name in SAS and the code looks like super heavy.
Is there any other ways to do that without redundant code? Or to avoid write each specific name of variable? In SAS.
Any ideas are appreciated!!
sas statistics
This ends up just being a lookup problem. At some point you have to define how you want them grouped, and then apply the groups. It's actually easier to create 49 dummy variables cause you don't have to think there.
– Reeza
Nov 10 at 0:39
Please post your actual attempts in the future.
– Reeza
Nov 10 at 0:42
@Reeza Thank you for your response. I did it in the same way as your first method, by using the IF/THEN statement. But your second method is brand new for me. It seems like hard to avoid typing the words from variable...
– 史超南
Nov 10 at 21:00
Well yes, if there’s not a clear logical order the computer can only do what you tell you it. If there’s some sort of logic (eg order of vars, such as groups of 5, or alphabetically) you have other options.
– Reeza
Nov 11 at 0:27
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am working with SAS and want to record variable which with over 50+ different qualitative dummies. For example, the state of the U.S.
In this case, I just want to reduce them into 4 or 5 levels dummy as quantitative variable.
I get several ideaS, for example to use if/else statement, however, the problem is that i have to write down and specify each of area name in SAS and the code looks like super heavy.
Is there any other ways to do that without redundant code? Or to avoid write each specific name of variable? In SAS.
Any ideas are appreciated!!
sas statistics
I am working with SAS and want to record variable which with over 50+ different qualitative dummies. For example, the state of the U.S.
In this case, I just want to reduce them into 4 or 5 levels dummy as quantitative variable.
I get several ideaS, for example to use if/else statement, however, the problem is that i have to write down and specify each of area name in SAS and the code looks like super heavy.
Is there any other ways to do that without redundant code? Or to avoid write each specific name of variable? In SAS.
Any ideas are appreciated!!
sas statistics
sas statistics
asked Nov 10 at 0:02
史超南
225
225
This ends up just being a lookup problem. At some point you have to define how you want them grouped, and then apply the groups. It's actually easier to create 49 dummy variables cause you don't have to think there.
– Reeza
Nov 10 at 0:39
Please post your actual attempts in the future.
– Reeza
Nov 10 at 0:42
@Reeza Thank you for your response. I did it in the same way as your first method, by using the IF/THEN statement. But your second method is brand new for me. It seems like hard to avoid typing the words from variable...
– 史超南
Nov 10 at 21:00
Well yes, if there’s not a clear logical order the computer can only do what you tell you it. If there’s some sort of logic (eg order of vars, such as groups of 5, or alphabetically) you have other options.
– Reeza
Nov 11 at 0:27
add a comment |
This ends up just being a lookup problem. At some point you have to define how you want them grouped, and then apply the groups. It's actually easier to create 49 dummy variables cause you don't have to think there.
– Reeza
Nov 10 at 0:39
Please post your actual attempts in the future.
– Reeza
Nov 10 at 0:42
@Reeza Thank you for your response. I did it in the same way as your first method, by using the IF/THEN statement. But your second method is brand new for me. It seems like hard to avoid typing the words from variable...
– 史超南
Nov 10 at 21:00
Well yes, if there’s not a clear logical order the computer can only do what you tell you it. If there’s some sort of logic (eg order of vars, such as groups of 5, or alphabetically) you have other options.
– Reeza
Nov 11 at 0:27
This ends up just being a lookup problem. At some point you have to define how you want them grouped, and then apply the groups. It's actually easier to create 49 dummy variables cause you don't have to think there.
– Reeza
Nov 10 at 0:39
This ends up just being a lookup problem. At some point you have to define how you want them grouped, and then apply the groups. It's actually easier to create 49 dummy variables cause you don't have to think there.
– Reeza
Nov 10 at 0:39
Please post your actual attempts in the future.
– Reeza
Nov 10 at 0:42
Please post your actual attempts in the future.
– Reeza
Nov 10 at 0:42
@Reeza Thank you for your response. I did it in the same way as your first method, by using the IF/THEN statement. But your second method is brand new for me. It seems like hard to avoid typing the words from variable...
– 史超南
Nov 10 at 21:00
@Reeza Thank you for your response. I did it in the same way as your first method, by using the IF/THEN statement. But your second method is brand new for me. It seems like hard to avoid typing the words from variable...
– 史超南
Nov 10 at 21:00
Well yes, if there’s not a clear logical order the computer can only do what you tell you it. If there’s some sort of logic (eg order of vars, such as groups of 5, or alphabetically) you have other options.
– Reeza
Nov 11 at 0:27
Well yes, if there’s not a clear logical order the computer can only do what you tell you it. If there’s some sort of logic (eg order of vars, such as groups of 5, or alphabetically) you have other options.
– Reeza
Nov 11 at 0:27
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Method 1:
Use IN, but you still have to list the variables. You can also do it via a format, but you have to define the format first anyways.
if state in ('AL', 'AK', 'AZ' ... etc) then state_group = 1;
else if state in ( .... ) then state_group = 2;
Method 2:
For a format, you create format using PROC FORMAT and then apply it.
proc format;
value $ state_grp_fmt
'AL', 'AK', 'AZ' = 1
'DC', 'NC' = 2 ;
run;
And then you can use it with a PUT statement.
State_Group = put(state, state_grp_fmt);
Brilliant response
– 史超南
Nov 10 at 21:01
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Method 1:
Use IN, but you still have to list the variables. You can also do it via a format, but you have to define the format first anyways.
if state in ('AL', 'AK', 'AZ' ... etc) then state_group = 1;
else if state in ( .... ) then state_group = 2;
Method 2:
For a format, you create format using PROC FORMAT and then apply it.
proc format;
value $ state_grp_fmt
'AL', 'AK', 'AZ' = 1
'DC', 'NC' = 2 ;
run;
And then you can use it with a PUT statement.
State_Group = put(state, state_grp_fmt);
Brilliant response
– 史超南
Nov 10 at 21:01
add a comment |
up vote
1
down vote
Method 1:
Use IN, but you still have to list the variables. You can also do it via a format, but you have to define the format first anyways.
if state in ('AL', 'AK', 'AZ' ... etc) then state_group = 1;
else if state in ( .... ) then state_group = 2;
Method 2:
For a format, you create format using PROC FORMAT and then apply it.
proc format;
value $ state_grp_fmt
'AL', 'AK', 'AZ' = 1
'DC', 'NC' = 2 ;
run;
And then you can use it with a PUT statement.
State_Group = put(state, state_grp_fmt);
Brilliant response
– 史超南
Nov 10 at 21:01
add a comment |
up vote
1
down vote
up vote
1
down vote
Method 1:
Use IN, but you still have to list the variables. You can also do it via a format, but you have to define the format first anyways.
if state in ('AL', 'AK', 'AZ' ... etc) then state_group = 1;
else if state in ( .... ) then state_group = 2;
Method 2:
For a format, you create format using PROC FORMAT and then apply it.
proc format;
value $ state_grp_fmt
'AL', 'AK', 'AZ' = 1
'DC', 'NC' = 2 ;
run;
And then you can use it with a PUT statement.
State_Group = put(state, state_grp_fmt);
Method 1:
Use IN, but you still have to list the variables. You can also do it via a format, but you have to define the format first anyways.
if state in ('AL', 'AK', 'AZ' ... etc) then state_group = 1;
else if state in ( .... ) then state_group = 2;
Method 2:
For a format, you create format using PROC FORMAT and then apply it.
proc format;
value $ state_grp_fmt
'AL', 'AK', 'AZ' = 1
'DC', 'NC' = 2 ;
run;
And then you can use it with a PUT statement.
State_Group = put(state, state_grp_fmt);
answered Nov 10 at 0:42
Reeza
13k21126
13k21126
Brilliant response
– 史超南
Nov 10 at 21:01
add a comment |
Brilliant response
– 史超南
Nov 10 at 21:01
Brilliant response
– 史超南
Nov 10 at 21:01
Brilliant response
– 史超南
Nov 10 at 21:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234814%2fhow-to-record-qualitative-variable-with-over-100-dummies-to-several-levels-as-qu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This ends up just being a lookup problem. At some point you have to define how you want them grouped, and then apply the groups. It's actually easier to create 49 dummy variables cause you don't have to think there.
– Reeza
Nov 10 at 0:39
Please post your actual attempts in the future.
– Reeza
Nov 10 at 0:42
@Reeza Thank you for your response. I did it in the same way as your first method, by using the IF/THEN statement. But your second method is brand new for me. It seems like hard to avoid typing the words from variable...
– 史超南
Nov 10 at 21:00
Well yes, if there’s not a clear logical order the computer can only do what you tell you it. If there’s some sort of logic (eg order of vars, such as groups of 5, or alphabetically) you have other options.
– Reeza
Nov 11 at 0:27