BookmarkSubscribeRSS Feed
peiy5920
Calcite | Level 5

Hi all,

my code like this:

proc univariate data=PROJECT.PAPER_CRIC; var PCR_URINE_COMBINED; output out=perc pctlpre=p_ pctlpts= 33.33 66.67; run;

 

From the result of code, I already knew 2 points of the variable according to 33.33 and 66.67, then how can I create 3 parts of this variables(first,2nd,3rd), that is from continuous variable to categorical variable. Can someone show me some example codes? Thanks.

3 REPLIES 3
PGStats
Opal | Level 21

Call on proc rank to do this:

 

proc rank data=PROJECT.PAPER_CRIC out=perc groups=3; 
var PCR_URINE_COMBINED; 
ranks PCR_URINE_COMBINED_GRP;
run;
PG
PaigeMiller
Diamond | Level 26

If you want to split the data into thirds, use PROC RANK

 

proc rank data=have groups=3 out=want;
     var myvariablename;
     ranks tertiles;
run;

The variable tertiles will contain values 1 2 or 3, depending on whether they are in the bottom third, middle third or top third.

--
Paige Miller
ballardw
Super User

Or if you want to display a value, such as "Low" "Mid" "High" using the information you have create a custom format:

 

proc format library=work;
value LMH
0 - <33.33 = 'Low'
33.33 - < 66.67 = 'Mid'
66.67 - high = 'High';

data example;
/* just creating some values
between 0 and 100*/
do i= 1 to 1000;
   value = 100*rand('uniform');
   output;
end;
run;

proc freq data=example;
   tables value;
   format value LMH. ;
run;

The < in the value lists in Proc Format indicate whether an end point value is included (no <) or excluded from the interval.

The format could be used for the variable in any of the reporting procedures such as Proc Print, Report or Tabulate, or other analysis procedures to create analysis groups, or in graphing procedures to create and label groups.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 4823 views
  • 0 likes
  • 4 in conversation