lundi 2 décembre 2019

Creating subgroups while keeping group

I have a SAS dataset, where each row contains information about firms. There is a variable about the sector of the company; sect. There are up to 700 sectors, so I need to group them, like:

Industry: mining, textiles industry, food industry... and so on. I do this with the following code:

data temp; set in.data;

if sect in ('01' '02' '03' '04' '05' '06')    then my_sector='Industry' ;

run;

The tricky part is ; I also want to give out details within each sector. For instance, I want to keep this whole "Industry" sector, but I also want to have subgroups within "Industry". But when I run the following code:

data temp; set in.data;

if sect in ('01' '02' '03' '04' '05' '06')    then my_sector='Industry' ;

if sect in ('01' '02')    then my_sector='Textile Industry' ;
if sect in ('03' '04')    then my_sector='Food Industry' ;
if sect in ('05')         then my_sector='Mining Industry' ;

run;

The subgroups work just fine, but the global "Industry" sector only contains what is not contained in other subgroups (here the sector 06). So mu question is; how do I have the 3 subgroups but also an "Industry" sector that has all the 3 subgroups and the rest of the industry (from 01 to 06)?

Thank you very much,

Aucun commentaire:

Enregistrer un commentaire