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

tcddn is values like 1,2,3,4 for 4 cohorts, tcddn is something i want to display which is 9.2, 5, 1, 2.3 but they are not in numerical order. how do i resolve it? i don't want to display tcddn value in plot but want to order it by tcddn.
data combo1;
merge combo (in=a) want(in=b);
by subjid tcddn tcdd retestcd nu month;
if b;
keep subjid restresn month tcddn tcdd nu;
proc sort; by tcddn tcdd subjid nu month;
run;

 

proc sgplot data= combo1;
xaxis grid type= discrete discreteorder= data;
series x = month y= RESTRESN/ group=subjid grouporder= data;
scatter x=month y= RESTRESN/ group= subjid grouporder=data ;
xaxis label= 'Month';
yaxis label= 'ppFEV1 (%)'
values=(30 to 110 by 10);
by tcdd;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

This does not look like it has anything to do with what PROC you are trying to run.

 

Your BY statements do not line up.

You sorted by tcddn tcdd

But told the PROC to process by tcdd.

 

Two choices.

  • Add the NOTSORTED keyword to the second BY statement to tell the PROC that the groups are grouped, but not sorted.
  • Add TCDDN to the second BY statement, but set the NOBYLINE option and use the #BYVAL() tags in the title statement to reference the value of TCDD where ever you want to place it in the TITLE.

 

 

View solution in original post

6 REPLIES 6
DanH_sas
SAS Super FREQ

What do you get if you change your sort this way?

proc sort; by tcdd month tcddn;
run;

dsam
Fluorite | Level 6
I tried it, but month which is not numeric variable, order is messed up on x axis.
DanH_sas
SAS Super FREQ

In that case, I would create a numeric column with values 1 to 12 mapping to the correct month. Then, use a user-defined format to map the value back to the string name.

PaigeMiller
Diamond | Level 26

@dsam wrote:
I tried it, but month which is not numeric variable, order is messed up on x axis.

Important concept: months and any calendar information in SAS data sets should be stored in NUMERIC variables. In fact, let me say that even more strongly: any calendar information in SAS data sets MUST be stored in NUMERIC variables. Character variables will not sort in the desired order for calendar information.

--
Paige Miller
Ksharp
Super User

That would be very helpful if you could post some dummy data and desired output to display the issue you are running into.

 

data have;
call streaminit(123);
do tcddn=1 to 4;
 do subjid=1 to 2;
   do month=1 to 12;
     RESTRESN=rand('normal');output;
   end;
  end;
end;
run;

proc format;
value fmt
1='   9.2'
2='  5'
3=' 1'
4='2.3'
;

data combo1;
 set have;
 tcdd=put(tcddn,fmt8.);
run;
proc sort data=combo1;
by tcdd;
run;

option nobyline;
title "tcdd=#byval1";
 proc sgplot data= combo1;
xaxis grid type= discrete discreteorder= data;
series x = month y= RESTRESN/markers group=subjid grouporder= data;
xaxis label= 'Month';
yaxis label= 'ppFEV1 (%)';
by tcdd;
run;
Tom
Super User Tom
Super User

This does not look like it has anything to do with what PROC you are trying to run.

 

Your BY statements do not line up.

You sorted by tcddn tcdd

But told the PROC to process by tcdd.

 

Two choices.

  • Add the NOTSORTED keyword to the second BY statement to tell the PROC that the groups are grouped, but not sorted.
  • Add TCDDN to the second BY statement, but set the NOBYLINE option and use the #BYVAL() tags in the title statement to reference the value of TCDD where ever you want to place it in the TITLE.

 

 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 616 views
  • 2 likes
  • 5 in conversation