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!!










share|improve this question






















  • 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















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!!










share|improve this question






















  • 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













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!!










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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);





share|improve this answer





















  • Brilliant response
    – 史超南
    Nov 10 at 21:01











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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);





share|improve this answer





















  • Brilliant response
    – 史超南
    Nov 10 at 21:01















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);





share|improve this answer





















  • Brilliant response
    – 史超南
    Nov 10 at 21:01













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);





share|improve this answer












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);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 0:42









Reeza

13k21126




13k21126












  • Brilliant response
    – 史超南
    Nov 10 at 21:01


















  • Brilliant response
    – 史超南
    Nov 10 at 21:01
















Brilliant response
– 史超南
Nov 10 at 21:01




Brilliant response
– 史超南
Nov 10 at 21:01


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff