BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
novinosrin
Tourmaline | Level 20

Hello Folks, I would appreciate if you could help me with appropriate syntax/solution for visualization using SGPANEL.

I have a dataset  that has an array of variables, I want to display visuals for pairs. Basically, the data has a set of Actuals and Model variables. I would like a visual for Actual1 vs Model1 upto actN v modN with Period(Month) in X axis. 

I could split the data using the below and then the sequential/manual SGPLOT seems to work fine. However, my need is a Panel view for all cohort groups in one. Please advice.

 

The approach:


/*Prepare data for graph by Splitting into period,actN,modN */
data _null_;
 if _n_=1 then do;
  dcl hash H1 () ;
  h1.definekey  ("n") ;
  h1.definedata ("n",'h') ;
  h1.definedone () ;
 end;
 set crrl.qrm_act_mod end=z;
 array a act_total--act_180d;
 array b mod_total--mod_180d;
 do n=1 to dim(a);
  if h1.find() ne 0 then do;
   dcl hash h(ordered:'a');
   h.definekey('cohort','period');
   h.definedata('cohort','period',vname(a(n)),vname(b(n )));
   h.definedone();
   h1.add();
  end;
  h.add();
 end;
 if z;
 dcl hiter hi('h1');
 do while(hi.next()=0);
  h.output(dataset:catx('_','C_var',n));
 end;
run;
/*if I do this for each cohort one by one, it works*/
proc sgplot data=c_var_8;
 where cohort=4;
 vline period / response=act_180d  markers;
 vline period / response=mod_180d  markers y2axis;
run;
/*The below one is what I desire, though unsuccessful*/
proc sgpanel data=c_var_8;
  panelby cohort;
  vline period / response=act_180d  markers;
/*  vline period / response=mod_180d  markers y2axis;????????*/
run;

Thank you in advance!

 

Absolute novice in visualization. So kindly bear with me please. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SylvainTremblay
SAS Employee

With the sample source data you provided, it would look like this:

 

data table;
   infile datalines missover;
   input cohort date MONYY7. actual model;
   format date MONYY7.;
   datalines;
1 Mar2020  0.4 0.5
1 Apr2020  0.5 0.8
1 May2020  0.3 0.6
2 Mar2020  0.8 0.7
2 Apr2020  0.8 0.9
2 May2020  0.5 0.6
;
run;

proc sort data=table out=table_s;
   by cohort date;
run; 

proc transpose 
   data=table_s
   out=table_s_t(rename=(col1=Measurement _NAME_=Source));
   var actual model;
   by cohort date;
run;

proc datasets library=work nolist;
   modify table_s_t;
   label Source='Source' Measurement="Measurement";
quit;

title "Panel of LineChart Actual vs Model by Cohort";
proc sgpanel data=table_s_t;
  panelby cohort / spacing=5 novarname;
  vline date / response=Measurement group=Source;
run;

SylvainTremblay_0-1601407868092.png

 

 

View solution in original post

5 REPLIES 5
ballardw
Super User

Without out some data to see what things look like in the sgplot hard to tell why sgpanel isn't quite what you want.

 

What is problem with the result? Since there aren't any options on the panel by statement any issue revolving around order of display my be attributed to use of defaults for all the panel by characteristics.

 

Unless you are actually needing to use Vline to work with Vbar it might be that Series is more appropriate for your purpose.

SylvainTremblay
SAS Employee

Indeed, without seeing your data, it is hard to propose the right solution.

 

Having said that, before graphing, you need to have the data in the right form to support the type of graph you need. If you have a wide table, you can use Proc Transpose to create a narrow version of your data. This example for the documentation of Proc Transpose illustrates this: 

 

Example 4: Transposing BY Groups

https://go.documentation.sas.com/?docsetId=proc&docsetTarget=p03avwj37ggkpkn1mzqzkmwvk1sl.htm&docset...

 

Once the data is in the right form (narrow table), you can use Proc SGPANEL.

 

Cheers!

Sylvain

 

options nodate pageno=1 linesize=80 pagesize=40;
data fishdata;
infile datalines missover;
input Location & $10. Date date7.
Length1 Weight1 Length2 Weight2 Length3 Weight3
Length4 Weight4;
format date date7.;
datalines;
Cole Pond 2JUN95 31 .25 32 .3 32 .25 33 .3
Cole Pond 3JUL95 33 .32 34 .41 37 .48 32 .28
Cole Pond 4AUG95 29 .23 30 .25 34 .47 32 .3
Eagle Lake 2JUN95 32 .35 32 .25 33 .30
Eagle Lake 3JUL95 30 .20 36 .45
Eagle Lake 4AUG95 33 .30 33 .28 34 .42
;
run;


proc transpose data=fishdata
   out=fishlength(rename=(col1=Measurement));
   var length1-length4;
   by location date;
run;

 

proc sgpanel data=fishlength;
   panelby location / spacing=5 novarname;
   vline date / response=Measurement group=_NAME_;
run;

 

 

novinosrin
Tourmaline | Level 20

Thank you both @SylvainTremblay / @ballardw  First off, my apologies to have not posted a sample which I kinda presumed the explanation of actual vs model plain numeric pcts is something a piece of cake for you.  The data looks like the below, ordered by cohort. The cohort(groups) could be any amount.

 

cohort     date(Month)  Act   Model

   1            Mar2020       0.4     0.5

    1           Apr 2020       0.5    0.8

     1           May2020       0.3   0.6

and so on....

 

I would like a panel view for each cohort where Date(month) in Xaxis and a line chart of act and model pct values. 

If the values were dollar amounts and not percents(decimals) unlike the above, I would rather prefer bar chart to view the comparison. 

SylvainTremblay
SAS Employee

With the sample source data you provided, it would look like this:

 

data table;
   infile datalines missover;
   input cohort date MONYY7. actual model;
   format date MONYY7.;
   datalines;
1 Mar2020  0.4 0.5
1 Apr2020  0.5 0.8
1 May2020  0.3 0.6
2 Mar2020  0.8 0.7
2 Apr2020  0.8 0.9
2 May2020  0.5 0.6
;
run;

proc sort data=table out=table_s;
   by cohort date;
run; 

proc transpose 
   data=table_s
   out=table_s_t(rename=(col1=Measurement _NAME_=Source));
   var actual model;
   by cohort date;
run;

proc datasets library=work nolist;
   modify table_s_t;
   label Source='Source' Measurement="Measurement";
quit;

title "Panel of LineChart Actual vs Model by Cohort";
proc sgpanel data=table_s_t;
  panelby cohort / spacing=5 novarname;
  vline date / response=Measurement group=Source;
run;

SylvainTremblay_0-1601407868092.png

 

 

novinosrin
Tourmaline | Level 20

Sweet @SylvainTremblay   Thank you sooooooooo much!! Can't appreciate enough!!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 575 views
  • 0 likes
  • 3 in conversation