DATA Step, Macro, Functions and more

Function freq and not proc freq

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

Function freq and not proc freq

Hi,

 

I have a big table with lots of observations and i want to manipulate/transform my data. Here is my problem:

 

PROC SQL;
   CREATE TABLE WORK.Lista AS 
   SELECT t1.Name, 
                  t1.ID, 
                  t1.Description, 
                   /* Calculation Number */
          (case when t1.Description EQ 'PROT' then FREQ(t1.Description)
            end) AS Number
      FROM WORK.TOTAL t1
      GROUP BY t1.ID
      ORDER BY t1.Name ASC;
QUIT;

I do not want to have a report of "proc freq". The idea is make a new query with a new variable(Number) and continue the program.

 

I want count only when Description = 'PROT' and not when is different. It is dificult to find the arguments of function freq. What i have to do is to call freq with a condition inside the function, and not outside(that's happen now). But the new collumn(Number) must appear in all observations, also when observation with t1.Description NE 'PROT' must have the count of all 'PROT'

 

Regards,

Aleixo


Accepted Solutions
Solution
‎03-26-2018 11:19 AM
Respected Advisor
Posts: 3,270

Re: Function freq and not proc freq

[ Edited ]
SELECT t1.Name, t1.ID, 
          count(t1.description) AS Number
      FROM WORK.TOTAL t1 
      where t1.description eq 'PROT'
      GROUP BY t1.ID
--
Paige Miller

View solution in original post


All Replies
Solution
‎03-26-2018 11:19 AM
Respected Advisor
Posts: 3,270

Re: Function freq and not proc freq

[ Edited ]
SELECT t1.Name, t1.ID, 
          count(t1.description) AS Number
      FROM WORK.TOTAL t1 
      where t1.description eq 'PROT'
      GROUP BY t1.ID
--
Paige Miller
Contributor
Posts: 70

Re: Function freq and not proc freq

Posted in reply to PaigeMiller

Very nice. Works very well.

 

I have to use more times the statement 'where' in that location of proc sql

 

thanks a lot

 

And thanks other answers xD

 

Occasional Contributor
Posts: 6

Re: Function freq and not proc freq

why don't you use the function count() instead of freq?? 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 120 views
  • 0 likes
  • 3 in conversation