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

I tried ("cou" is 1,2,3,4,5.....; "var" is continuous variable with decimal points):

proc sql;
    create table mt as
    select cou,
           pctl(75, var) as var_p75
    from check_1
    group by cou;
quit;

But it returns me with multiple rows per cou.

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

SQL is not the best tool for this job.

I'd use Proc Univariate, here is nice example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_examples08.htm

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
yabwon
Onyx | Level 15

SQL is not the best tool for this job.

I'd use Proc Univariate, here is nice example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_examples08.htm

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



PaigeMiller
Diamond | Level 26

While SQL might or might not be able to do this, it is a lot more programming than PROC UNIVARIATE/PROC MEANS/PROC SUMMARY and of course SAS has already tested and debugged these PROCs so you can be sure the answer is correct. If you program it yourself in SQL, I think you have to test, debug and vouch for the accuracy of what you are doing.

--
Paige Miller
FreelanceReinh
Jade | Level 19

Just to add the explanation why your approach doesn't work and you should use a different procedure, as others have already suggested:

 

The PCTL function (unlike the MEDIAN function) is not among the PROC SQL summary functions. Hence, it is not applied to the variable (columnvar, but to the single value of var in each observation (row). But for any non-missing numeric value the trivial equality pctl(75, var)=var holds. So, your output dataset MT contains variable cou and basically a copy of variable var, named var_p75, from the input dataset CHECK_1. In particular, it is not aggregated at all, as you have noticed.

 

You must have received a warning in the log about the absence of a summary function:

WARNING: A GROUP BY clause has been transformed into an ORDER BY clause because neither the SELECT clause nor the optional HAVING clause of the associated
         table-expression referenced a summary function.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 3 replies
  • 244 views
  • 3 likes
  • 4 in conversation