SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Jho1
Calcite | Level 5

Hi All, Sorry if it's already post, can't see the first 2 posts idid.

Can You please help to find out what’s wrong with my code, I’m trying to have spaghetti plot for 2 groups (TRTN), I want to control the color, the thickness, and symbols etc…by treatment. i.e all subjects within the same group have same color etc. The line plot are mixed up and do not display the correct values.

I want for TRT=1 RED LINE and solid.

For TRTN=2 BLUE LINE AND SHORTDASH

 

proc sgplot data=my_data;

   title1 'MY TITLTE';

   title2;

styleattrs datacontrastcolors=(red blue)

             datasymbols=(squarefilled trianglefilled)

             datalinepatterns=(Solid ShortDash);   

 

   series x=avisitn y=aval  / group=subjid grouplc=trtn  name='grouping'  Markers MARKERATTRS = (color = black) curvelabel;

   scatter x=avisitn y=aval / group = subjid name = 'subjid' markerattrs=(color = black );

   xaxis  display=all grid integer values=(12 13 14 15 16 17) valueshint;

   yaxis  LABEL = 'YLABEL)' grid;

    keylegend 'grouping' / type=linecolor;

run;

 

 

Here is my data

data my_data ;                                                                                                                            

   input subjid  avisit $  avisitn aval trt $ trtn;                                                                                               

   datalines;

20110100    Month3      14 2.9 A 1

20110101    Baseline    13    2.3   A     1

20110101    Month3      14    2     A     1

20110101    Month6      15    2.3   A     1

20110101    Month9      16    2.9   A     1

20110200    Baseline    13    2.7   A     1

20110200    Baseline    13    2.9   A     1

20110200    Month3      14    2     A     1

20110200    Month6      15    2     A     1

20110200    Month9      16    2     A     1

20110200    Month12     17    1.4   A     1

20110300    Baseline    13    2     A     1

20110300    Month3      14    1.8   A     1

20110300    Month6      15    2     A     1

20110600    Month3      14    2.9   A     1

20110200    Baseline    13    2.3   B     2

20110200    Baseline    13    2.3   B     2

20110200    Month3      14    2.7   B     2

20110200    Month6      15    2.3   B     2

20110200    Month9      16    2.5   B     2

20110200    Month12     17    2.3   B     2

20110600    Month3      14    2.9   B     2

;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You need change your data structure.

 

 

Ksharp:
data my_data ;                                                                                                                            
   input subjid  avisitn aval trtn;                                                                                               
   datalines;
1 1 1.2 1
1 2 1.4 1
1 3 1.6 1
1 4 1.8 1
2 1 2.2 1
2 2 2.4 1
2 3 2.6 1
2 4 2.8 1
3 1 3.2 2
3 2 3.4 2
3 3 3.6 2
3 4 3.8 2
4 1 4.2 2
4 2 4.4 2
4 3 4.6 2
4 4 4.8 2
;


proc sort data=my_data out=temp;
by trtn subjid avisitn;
run;


data temp2;
 merge temp(where=(trtn=1))
     temp(where=(_trtn=2) rename=(subjid=_subjid  avisitn=_avisitn aval=_aval trtn=_trtn)) ;
output;
call missing(of _all_);
run;

proc sgplot data=temp2 noautolegend;
   series x=avisitn y=aval  / group=subjid  lineattrs=(color=yellowgreen thickness=4 pattern=Solid )
                              markers markerattrs=(symbol=squarefilled size=12) ;
   series x=_avisitn y=_aval  / group=subjid   lineattrs=(color=red thickness=2  pattern=ShortDash ) 
                              markers markerattrs=(symbol=trianglefilled size=8) ;
run;

Ksharp_0-1658839004550.png

 

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

You need change your data structure.

 

 

Ksharp:
data my_data ;                                                                                                                            
   input subjid  avisitn aval trtn;                                                                                               
   datalines;
1 1 1.2 1
1 2 1.4 1
1 3 1.6 1
1 4 1.8 1
2 1 2.2 1
2 2 2.4 1
2 3 2.6 1
2 4 2.8 1
3 1 3.2 2
3 2 3.4 2
3 3 3.6 2
3 4 3.8 2
4 1 4.2 2
4 2 4.4 2
4 3 4.6 2
4 4 4.8 2
;


proc sort data=my_data out=temp;
by trtn subjid avisitn;
run;


data temp2;
 merge temp(where=(trtn=1))
     temp(where=(_trtn=2) rename=(subjid=_subjid  avisitn=_avisitn aval=_aval trtn=_trtn)) ;
output;
call missing(of _all_);
run;

proc sgplot data=temp2 noautolegend;
   series x=avisitn y=aval  / group=subjid  lineattrs=(color=yellowgreen thickness=4 pattern=Solid )
                              markers markerattrs=(symbol=squarefilled size=12) ;
   series x=_avisitn y=_aval  / group=subjid   lineattrs=(color=red thickness=2  pattern=ShortDash ) 
                              markers markerattrs=(symbol=trianglefilled size=8) ;
run;

Ksharp_0-1658839004550.png

 

 

Jho1
Calcite | Level 5
Thanks so much, Your help is appreciated.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1937 views
  • 0 likes
  • 2 in conversation