BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

dear all 

i have to create dummy variables based on the nic_code of the companies.

there are nearly 70 different nic_codes (which are not in serial order) for more than 5000 companies in my data set. So, i cannot do it manually in SAS. 

if there is any shortcut programming to do this, please let me know.

 

the sample of my dataset format is as follows

Company Namenic-code
20 Microns Ltd.8
3I Infotech Ltd.62
3M India Ltd.22
3P Land Holdings Ltd.64
3Rd Rock Multimedia Ltd.62
52 Weeks Entertainment Ltd.59
5Paisa Capital Ltd.66
63 Moons Technologies Ltd.46
7Nr Retail Ltd.47
7Seas Entertainment Ltd.62
8K Miles Software Services Ltd.62
A & M Febcon Ltd.46
A & M Jumbo Bags Ltd.22

 i need the output in the following format

please note that nic_coes are not in serial order from 1 to 100 and also all the codes from 1 to 100 are not present. . 

Company Namenic-codenic_dummy01nic_dummy02nic_dummy03…………..nic_dummy100
20 Microns Ltd.8     
3I Infotech Ltd.62     
3M India Ltd.22     
3P Land Holdings Ltd.64     
3Rd Rock Multimedia Ltd.62     
52 Weeks Entertainment Ltd.59     
5Paisa Capital Ltd.66     
63 Moons Technologies Ltd.46     
7Nr Retail Ltd.47     
7Seas Entertainment Ltd.62     
8K Miles Software Services Ltd.62     
A & M Febcon Ltd.46     
A & M Jumbo Bags Ltd.22     
A 2 Z Infra Engg. Ltd.71     
A A R Commercial Co. Ltd.64     
A A R V Infratel Ltd.46    

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
 set sashelp.class(keep=name);
 call streaminit(12345678);
 code=ceil(rand('uniform')*1000);
run;
data temp;
 set have;
 dummy=1;
run;

proc logistic data=temp outdesign=want outdesignonly noprint;
class code/param=glm;
model dummy=code/nofit noint;
run;
data final_want;
 merge have want(drop=dummy);
run;

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

So there are many SAS procedures that will compute the dummy variables for you, so you don't have to do it yourself. And thus, before you go about creating dummies, you would be wise to explain further what you are planning to do with this data.

--
Paige Miller
Ksharp
Super User
data have;
 set sashelp.class(keep=name);
 call streaminit(12345678);
 code=ceil(rand('uniform')*1000);
run;
data temp;
 set have;
 dummy=1;
run;

proc logistic data=temp outdesign=want outdesignonly noprint;
class code/param=glm;
model dummy=code/nofit noint;
run;
data final_want;
 merge have want(drop=dummy);
run;
srikanthyadav44
Quartz | Level 8
thank you Mr. Ksharp
the SAS code suggested by you, is working excellently.
It has solved by problems.
thanks a lot
smantha
Lapis Lazuli | Level 10
data have;
set have;
*Company Name	nic-code;
Dummy=1;
run;
proc sort data=have; by company_name; run;
proc transpose data=have out=want prefix=Dummy;
by company_name;
id nic_code;
var dummy;
run;
srikanthyadav44
Quartz | Level 8
thank you dear smantha for your valuable replay.
i am getting the output with dummy variables. but the missing values in the dummy variable are not filled with zero. all the missing values are blank.
I have to fill the missing values with zero. As there are large number of dummies, i cannot do it manual in SAS.
please suggest a code which can create dummies with 1 and 0 values, not just '1'.
thanks in advance
PaigeMiller
Diamond | Level 26

@srikanthyadav44 wrote:
thank you dear smantha for your valuable replay.
i am getting the output with dummy variables. but the missing values in the dummy variable are not filled with zero. all the missing values are blank.
I have to fill the missing values with zero. As there are large number of dummies, i cannot do it manual in SAS.
please suggest a code which can create dummies with 1 and 0 values, not just '1'.
thanks in advance

You could let many SAS PROCs generate the dummy variables for you, and then you don't have to do it yourself and potentially get it wrong.

--
Paige Miller
brian20435
Calcite | Level 5

@PaigeMiller, Reading through this thread, you replied twice about "letting many SAS procs generate the dummy variables for you" yet you never suggested what SAS procs to use or gave an example.  When people post a question here, they obviously don't know how to do it and are asking for help.  Simply stating that SAS can do it for you is not helpful in the least.  Notice how the other two that replied gave sample code. It may not be the most efficient but one of them apparently worked for @srikanthyadav44   .  You might as well have just replied..."go read the manual". Sorry, but replies like yours just waste time.

Kurt_Bremser
Super User

If you had taken the time to actually read @PaigeMiller 's posts, you would have found this.

 you would be wise to explain further what you are planning to do with this data.

@srikanthyadav44 never provided the details, so there is no way to know which procedure would get the final goal.

PaigeMiller
Diamond | Level 26

@brian20435 wrote:

@PaigeMiller, Reading through this thread, you replied twice about "letting many SAS procs generate the dummy variables for you" yet you never suggested what SAS procs to use or gave an example.  When people post a question here, they obviously don't know how to do it and are asking for help.  Simply stating that SAS can do it for you is not helpful in the least.  Notice how the other two that replied gave sample code. It may not be the most efficient but one of them apparently worked for @srikanthyadav44   .  You might as well have just replied..."go read the manual". Sorry, but replies like yours just waste time.


And I could send @srikanthyadav44 on a wild goose chase that will not help him further by suggesting PROC ABCDEF to create dummy variables, when that's not what he needs. Or I could name all the PROCs that will do this and let @srikanthyadav44 try each one to find the one that does what he wants. At no time did I say "read the manual". I said: explain what you need.

--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1828 views
  • 9 likes
  • 6 in conversation