简体   繁体   中英

SAS PROC FREQ BY variable not sorted Ascending how to display table

my datasete looks like the following (over500k data)

| ID_number| Age_group | value_x |value_y |

I 'm looking to use only proc freq

proc freq data=lib_d1.data_analyses;        
table value_x * value_y /list out=lib1_d1.table_freq_age_group;      
by Age_group;    
run;
     

The error I'm getting is that Age_group is not sorted ascending.

Is there a way for me to generate my output, within this proc freq. I do not want proc sort, proc tabulate, I'm looking within this proc freq?
Many thanks

Why not just add it to the TABLES statement?

proc freq data=lib_d1.data_analyses;
  table Age_group * value_x * value_y /list out=lib1_d1.table_freq_age_group;
run;

There is not a way to do this on a SAS dataset unless it is first sorted or indexed by age_group . An index will prevent you from needing to sort, but you'll have to recreate it if you remake the dataset.

proc datasets lib=lib_d1 nolist;
    modify data_analyses;
        index create age_group;
quit;

Note that CAS will handle unsorted/unindexed by-groups without an issue if you are on Viya.

A BY statement requires your data to be sorted ahead of time by the BY variables. If it's grouped but not explicitly ordered alphabetically you can use the NOTSORTED option.

This would be valid for the NOTSORTED option:

A
A
C
C
B 
B

So you can either not use a BY statement and do a three way table as @Tom suggested or otherwise you must pre-sort your data.

proc sort data=lib_d1.data_analyses;
by age_group;
run;

proc freq data=lib_d1.data_analyses;  
by age_group;      
table value_x * value_y /list out=lib1_d1.table_freq_age_group;   
run;

Since you're just doing counts you could just use PROC SQL, but you've indicated you don't want a solution outside of PROC FREQ Tom's solution is likely ideal for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM