10-22-2014 03:35 PM
I have 16 sectors in my dataset. I need to create dummy for each sector. It's very long if I write the code as follows:
if sector = 'Chemicals, rubber, plastics, non-metallic products' then Chemicals = 1; else Chemicals = 0;
if sector = 'Construction' then Construction = 1; else Construction = 0;
if sector = 'Education, Health' then Education = 1; else Education = 0;
Can I write the code shortly by using proc sql?
10-24-2014 06:51 PM
10-22-2014 04:06 PM
Seems to me that Array could be one of the solutions. The example can be expanded to adapt the number of variables that you have in your real data.
array dummy(3) Chemicals Construction Education;
do i=1 to dim (dummy);
10-24-2014 12:29 PM
Hi, one more question. If I want to group the sectors such as 1, 2, 3, ......, then what will be the code? For example, Chemicals will be 1, Construction will be 2, Education will be 3, ...........
10-24-2014 01:39 PM
proc glmmod data=yourdata outparm=parm outdesign=design;
See the SAS/STAT documentation for PROC GLMMOD for examples and definitions of the datasets created.
10-24-2014 03:44 PM
It's not working. Let me explain about my dataset. I have two variables in my dataset: company_code and sector. Say, company_100 is in chemicals sector, Company_200 is in Metal sector, ..... etc. Chemical sector will be 1, Metal sector will be 2, ..... etc.
10-24-2014 05:36 PM
The following is the sample of my dataset:
|ANN6748L1027||Machinery, equipment, furniture, recycling|
|BMG169621056||Food, beverages, tobacco|
I want to put sector code for each sector. Say, primary sector will be 1, machinery, equipment, furniture, recycling will be 2, ..... and so on.
10-24-2014 06:14 PM
In the output, one column will have to be created named sector_code. Output should be look like this;
company_code sector sector_code
|ANN6748L1027||Machinery, equipment, furniture, recycling||7|
|BMG169621056||Food, beverages, tobacco||4|
10-24-2014 06:22 PM
That's different than your original question, its a standard recode with if/then statements.
You can also use proc format if you want.
See this paper using the first example.
Need further help from the community? Please ask a new question.