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;
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.
What do you get if you change your sort this way?
proc sort; by tcdd month tcddn;
run;
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.
@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.
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;
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.
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →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.
Ready to level-up your skills? Choose your own adventure.