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

dear all 

my data is in the following format 

company_nameyearNIC
20 Microns Ltd.20118
Ashapura Minechem Ltd.20118
A D F Foods Ltd.201110
Adani Wilmar Ltd.201110
Agro Tech Foods Ltd.201110
Ajanta Soya Ltd.201110
Ambar Protein Inds. Ltd.201110
Andrew Yule & Co. Ltd.201110
Arcuttipore Tea Co. Ltd.201110
Associated Alcohols & Breweries Ltd.201111
Devyani International Ltd.201111
Eco Friendly Food Processing Park Ltd.201111
Elegant Floriculture & Agrotech (India) Ltd.201111
Flex Foods Ltd.201111
Freshtrop Fruits Ltd.201112
Sree Jayalakshmi Autospin Ltd.201112
A I Champdany Inds. Ltd.201113
A K Spintex Ltd.201113
A P M Industries Ltd.201113
Aarvee Denims & Exports Ltd.201113
Aditya Spinners Ltd.201113
Alka India Ltd.201113
Alok Industries Ltd.201113
Alps Industries Ltd.201113

i want the frequency of the NIC in next column as shown below 

company_nameyearNICNIC_Frequncy
20 Microns Ltd.201182
Ashapura Minechem Ltd.201182
A D F Foods Ltd.2011107
Adani Wilmar Ltd.2011107
Agro Tech Foods Ltd.2011107
Ajanta Soya Ltd.2011107
Ambar Protein Inds. Ltd.2011107
Andrew Yule & Co. Ltd.2011107
Arcuttipore Tea Co. Ltd.2011107
Associated Alcohols & Breweries Ltd.2011115
Devyani International Ltd.2011115
Eco Friendly Food Processing Park Ltd.2011115
Elegant Floriculture & Agrotech (India) Ltd.2011115
Flex Foods Ltd.2011115
Freshtrop Fruits Ltd.2011122
Sree Jayalakshmi Autospin Ltd.2011122
A I Champdany Inds. Ltd.2011138
A K Spintex Ltd.2011138
A P M Industries Ltd.2011138
Aarvee Denims & Exports Ltd.2011138
Aditya Spinners Ltd.2011138
Alka India Ltd.2011138
Alok Industries Ltd.2011138
Alps Industries Ltd.2011138

 

please suggest me a SAS to generate the frequency of the NIC as shown above 

 

thanking you in advance 

1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ

@PaigeMiller's code does provide that variable in the output unless I'm missing something.

data have;
infile datalines dlm = ',' dsd;
input company :$50. year nic;
datalines;
20 Microns Ltd.,2011,8
Ashapura Minechem Ltd.,2011,8
A D F Foods Ltd.,2011,10
Adani Wilmar Ltd.,2011,10
Agro Tech Foods Ltd.,2011,10
Ajanta Soya Ltd.,2011,10
Ambar Protein Inds. Ltd.,2011,10
Andrew Yule & Co. Ltd.,2011,10
Arcuttipore Tea Co. Ltd.,2011,10
Associated Alcohols & Breweries Ltd.,2011,11
Devyani International Ltd.,2011,11
Eco Friendly Food Processing Park Ltd.,2011,11
Elegant Floriculture & Agrotech (India) Ltd.,2011,11
Flex Foods Ltd.,2011,11
Freshtrop Fruits Ltd.,2011,12
Sree Jayalakshmi Autospin Ltd.,2011,12
A I Champdany Inds. Ltd.,2011,13
A K Spintex Ltd.,2011,13
A P M Industries Ltd.,2011,13
Aarvee Denims & Exports Ltd.,2011,13
Aditya Spinners Ltd.,2011,13
Alka India Ltd.,2011,13
Alok Industries Ltd.,2011,13
Alps Industries Ltd.,2011,13
;
run;

proc freq data=have;
     tables nic/noprint out=nic_frequency;
run;
data want;
    merge have nic_frequency(keep=nic count);
    by nic;
run;

maguiremq_0-1659095771180.png

It's just named `COUNT` which is an automatic variable from `PROC FREQ`. You can rename it on the `MERGE` statement.

 

Please mark Paige's response as the correct one.

View solution in original post

13 REPLIES 13
PaigeMiller
Diamond | Level 26

Use PROC FREQ, then merge the results with the original

 

UNTESTED CODE

proc freq data=have;
     tables nic/noprint out=nic_frequency;
run;
data want;
    merge have nic_frequency(keep=nic count);
    by nic;
run;
--
Paige Miller
srikanthyadav44
Quartz | Level 8
thanks for your prompt reply
but, i need frequency as a separate variable as i shown my query.
please suggest me a code
PaigeMiller
Diamond | Level 26

I provided untested code

--
Paige Miller
srikanthyadav44
Quartz | Level 8
thanks a lot for your prompt reply
i tried with this code
but i am not getting the output as i want
PaigeMiller
Diamond | Level 26

@srikanthyadav44 wrote:
thanks a lot for your prompt reply
i tried with this code
but i am not getting the output as i want

For your future benefit ... when you are not getting the output you want ... please SHOW US a screen capture of the output you are getting and explain what it is you want. If you just stop after you say "i am not getting the output as I want", we cannot help you, we don't know what that means, we don't know what you are seeing or what you want.

 

To provide a screen capture, please click on the "Insert Photos" icon to include your screen capture in your reply. Do not attach files.

--
Paige Miller
srikanthyadav44
Quartz | Level 8

 i am attaching the output

maguiremq
SAS Super FREQ

@PaigeMiller's code does provide that variable in the output unless I'm missing something.

data have;
infile datalines dlm = ',' dsd;
input company :$50. year nic;
datalines;
20 Microns Ltd.,2011,8
Ashapura Minechem Ltd.,2011,8
A D F Foods Ltd.,2011,10
Adani Wilmar Ltd.,2011,10
Agro Tech Foods Ltd.,2011,10
Ajanta Soya Ltd.,2011,10
Ambar Protein Inds. Ltd.,2011,10
Andrew Yule & Co. Ltd.,2011,10
Arcuttipore Tea Co. Ltd.,2011,10
Associated Alcohols & Breweries Ltd.,2011,11
Devyani International Ltd.,2011,11
Eco Friendly Food Processing Park Ltd.,2011,11
Elegant Floriculture & Agrotech (India) Ltd.,2011,11
Flex Foods Ltd.,2011,11
Freshtrop Fruits Ltd.,2011,12
Sree Jayalakshmi Autospin Ltd.,2011,12
A I Champdany Inds. Ltd.,2011,13
A K Spintex Ltd.,2011,13
A P M Industries Ltd.,2011,13
Aarvee Denims & Exports Ltd.,2011,13
Aditya Spinners Ltd.,2011,13
Alka India Ltd.,2011,13
Alok Industries Ltd.,2011,13
Alps Industries Ltd.,2011,13
;
run;

proc freq data=have;
     tables nic/noprint out=nic_frequency;
run;
data want;
    merge have nic_frequency(keep=nic count);
    by nic;
run;

maguiremq_0-1659095771180.png

It's just named `COUNT` which is an automatic variable from `PROC FREQ`. You can rename it on the `MERGE` statement.

 

Please mark Paige's response as the correct one.

srikanthyadav44
Quartz | Level 8
the code is working well.
but, i want to generate the frequency for each year, which I could not show in the sample.
i am sorry for the inconvenience.
please let me know how to rewrite the query to generate the nic frequency for every year separately.
my original data is from the year 2011 to 2021.

thanking you in advance
srikanthyadav44
Quartz | Level 8

dear all

i have my data in the following frequency 

company_nameyearNIC
20 Microns Ltd.20118
Ashapura Minechem Ltd.20118
A D F Foods Ltd.201110
Adani Wilmar Ltd.201110
Agro Tech Foods Ltd.201110
Ajanta Soya Ltd.201110
Ambar Protein Inds. Ltd.201110
A I Champdany Inds. Ltd.201113
A K Spintex Ltd.201113
A P M Industries Ltd.201113
Aarvee Denims & Exports Ltd.201113
Aditya Spinners Ltd.201113
A D F Foods Ltd.201210
Adani Wilmar Ltd.201210
Agro Tech Foods Ltd.201210
Ajanta Soya Ltd.201210
Andrew Yule & Co. Ltd.201210
Arcuttipore Tea Co. Ltd.201210
Associated Alcohols & Breweries Ltd.201213
Devyani International Ltd.201213
Eco Friendly Food Processing Park Ltd.201213
Acknit Industries Ltd.201214
Apis India Ltd.201214

 

 

 

 

I  have to generate the frequency of the NIC code for each year from 2011 to 2021 in the dataset.

I need the output in the following  format 

company_nameyearNICNIC_Frequency
20 Microns Ltd.201182
Ashapura Minechem Ltd.201182
A D F Foods Ltd.2011105
Adani Wilmar Ltd.2011105
Agro Tech Foods Ltd.2011105
Ajanta Soya Ltd.2011105
Ambar Protein Inds. Ltd.2011105
A I Champdany Inds. Ltd.2011135
A K Spintex Ltd.2011135
A P M Industries Ltd.2011135
Aarvee Denims & Exports Ltd.2011135
Aditya Spinners Ltd.2011135
A D F Foods Ltd.2012106
Adani Wilmar Ltd.2012106
Agro Tech Foods Ltd.2012106
Ajanta Soya Ltd.2012106
Andrew Yule & Co. Ltd.2012106
Arcuttipore Tea Co. Ltd.2012106
Associated Alcohols & Breweries Ltd.2012133
Devyani International Ltd.2012133
Eco Friendly Food Processing Park Ltd.2012133
Acknit Industries Ltd.2012142
Apis India Ltd.2012142

please suggest me a SAS code. in the earlier query,my illustrated output was not clear.

i have multiple years of data as mentioned in the table. and I need NIC frequency  for each year separately.

 

thanking you in advance  

Kurt_Bremser
Super User

Use the auto-remerge of PROC SQL:

proc sql;
create table want as
  select
    company_name,
    year,
    nic,
    count(*) as nic_frequency
  from have
  group by year, nic
;
quit;

Untested, for lack of usable example data; for tested code, provide example data in a working data step with datalines.

PaigeMiller
Diamond | Level 26

In your other thread, you were shown a correct answer (you must have marked it correct) and also how to change your data into SAS code with DATALINES. Please don't keep asking the same question after it has been answered correctly. Please don't keep posting this data as you have been doing; please post it as SAS code with DATALINES.

--
Paige Miller
Kurt_Bremser
Super User

I merged this back.

DO NOT DOUBLE_POST!!!

 

Provide usable example data as shown; if code provided as a suggestion does not work as intended, post the log and describe in detail where the result does not meet your expectations

Ksharp
Super User
proc sql;
create table want as
select *,count(*) as nic_freqency 
 from have
  group by nic;
quit;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 13 replies
  • 2231 views
  • 1 like
  • 5 in conversation