non complete proc boxplot in SAS - sas

I have this kind of code.
title 'Dispersion de Poids par chaque Produit et filiere';
proc sort data=tClassSASM; by filiere Produit PoidsN; run;
proc boxplot data=tClassSASM;
plot PoidsN*Produit/ nohlabel Vref=5,57,177 boxstyle=schematicid;
label PoidsN='Poids Despersion (g)';
run;
This is the output. But whatever I do I cannot find how to delete the red crossed headline, regroup the variables marked in red and give colors to vref lines. Can you help ?

Presuming filiere takes on the values X and Y
Turn off ODS GRAPHICS so the cvref= plot option is used.
ods graphics off;
title 'Dispersion de Poids par chaque Produit et filiere';
proc sort data=tClassSASM;
by filiere Produit PoidsN;
run;
proc boxplot data=tClassSASM;
* plot PoidsN*Produit/ nohlabel Vref=5,57,177 boxstyle=schematicid;
plot PoidsN*filiere/ nohlabel Vref=5,57,177 cvref=RED boxstyle=schematicid;
label PoidsN='Poids Despersion (g)';
run;
If you want a different color for each vref you will probably have to also use annotation data (anno= option).

Related

SAS: How do I rename an axis label name on sgplot scatter plot

I'm an Animal science student from Slovenia and I'm just finishing my master's thesis. For the finishing touches i need to make a bunch of scatter plots of different traits. All my data values (breeding values of different traits) are in code, for example m_pv10 (omišičenost = muscularity), m_pv31 (age of first calving),... To make the scatter plots easier to read i'd like to rename the x and y-axis labels from m_pv31 to "Age of first calving". I have tried renaming the values in a data step to bypass this problem but some names of the traits include spaces "age of first calving" and no nregular letters as "š" and "č" so the data step won't work.
data datam_copy;
set datam_copy;
rename m_pv10=Omišičenost;
m_pv31=Starost ob prvi telitvi;
m_pv12=Vime;run;
Is there a way to rename the axis labels directly in the sgplot code?
I would be very tratefull for any suggestions.
Urban
You can use the variable label, if that is the level you're working at. Here's an example.
data have;
set sashelp.class;
label age="Age of student"
height="Height of student"
weight="Weight of student"
;
run;
proc sgplot data=have;
vline age/response=height;
vline age/response=weight y2axis;
run;
You can rename the variable also of course, but this is really the job of the variable label. You can also use the label statement directly in sgplot.
proc sgplot data=sashelp.class;
vline age/response=height;
vline age/response=weight y2axis;
label age="Age of student"
height="Height of student"
weight="Weight of student"
;
run;
You can have spaces in the name but generally not a great idea though.
Not sure how the accents will work though.
options validvarname = any;
data datam_copy;
set datam_copy;
rename m_pv10= 'Omišičenost'n;
m_pv31= 'Starost ob prvi telitvi'n;
m_pv12= 'Vime'n;
run;

Logistic regression with BY statement ERROR message

I'm currently working on a SAS program that processes 50 logistic regression for 50 different samples. I previously had help on this thread (How to loop a logistic regression n number of times?), people advised me to use a BY statement to avoid looping this process n times. Works really well but I get this ERROR MESSAGE:
ERROR: No valid observations due either to missing values in the response, explanatory, frequency, or weight variable, or to
nonpositive frequency or weight values.
NOTE: The above message was for the following BY group:
Sample Replicate Number=.
You'll find my code below, if any of you have an idea of where does it come from, I'm open to anything, thank you in advance!
proc surveyselect data=TOP_1 NOPRINT out=ALEA_1
seed=0
method=urs
outhits
reps=5
n=300;
run;
proc surveyselect data=TOP_0 NOPRINT out=ALEA_0
seed=0
method=urs
outhits
reps=5
n=300;
run;
PROC SQL;
CREATE TABLE APPEND_TABLE As
SELECT * FROM ALEA_1
OUTER UNION CORR
SELECT * FROM ALEA_0;
QUIT;
/* Régression logistique*/
DATA WORK.TMP0TempTableAddtnlPredictData;
SET WORK.APPEND_TABLE(IN=__ORIG) WORK.BASE_PREDICT_2;
__FLAG=__ORIG;
__DEP=TOP_CREDIT_HABITAT_2017;
if not __FLAG then TOP_CREDIT_HABITAT_2017=.;
RUN;
PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
SELECT *
FROM WORK.TMP0TempTableAddtnlPredictData
ORDER BY REPLICATE;
QUIT;
TITLE;
TITLE1 "Résultats de la régression logistique";
FOOTNOTE;
FOOTNOTE1 "Généré par le Système SAS (&_SASSERVERNAME, &SYSSCPL) le %TRIM(%QSYSFUNC(DATE(), NLDATE20.)) à %TRIM(%SYSFUNC(TIME(), TIMEAMPM12.))";
PROC LOGISTIC DATA=WORK.SORTTempTableSorted
PLOTS(ONLY)=ROC
;
By Replicate;
CLASS age_classe (PARAM=EFFECT) Flag_bq_principale (PARAM=EFFECT) flag_univers_detenus (PARAM=EFFECT) csp_1 (PARAM=EFFECT) SGMT_FIDELITE (PARAM=EFFECT) situ_fam_1 (PARAM=EFFECT);
MODEL TOP_CREDIT_HABITAT_2017 (Event = '1') [...6## Heading ##] /
SELECTION=STEPWISE
SLE=0.1
SLS=0.1
INCLUDE=0
LINK=LOGIT
;
OUTPUT OUT=WORK.PREDLogRegPredictions(LABEL="Statistiques et prédictions de régression logistique pour WORK.APPEND_TABLE" WHERE=(NOT ws__FLAG))
PREDPROBS=INDIVIDUAL;
RUN;
QUIT;
DATA WORK.PREDLogRegPredictions;
set WORK.PREDLogRegPredictions;
TOP_CREDIT_HABITAT_2017=__DEP;
_FROM_=__DEP;
DROP __DEP;
DROP __FLAG;
RUN ;
QUIT ;
/* Création du fichier de sorti final*/
PROC SQL;
CREATE TABLE MODELE_RESULTS As
SELECT IDCLI_CALCULE, IP_1
FROM PREDLogRegPredictions;
RUN;
QUIT;
ODS GRAPHICS OFF;
Probably from this:
DATA WORK.TMP0TempTableAddtnlPredictData;
SET WORK.APPEND_TABLE(IN=__ORIG) WORK.BASE_PREDICT_2;
__FLAG=__ORIG;
__DEP=TOP_CREDIT_HABITAT_2017;
if not __FLAG then TOP_CREDIT_HABITAT_2017=.;
RUN;
You're appending a dataset that does not have a replicate number on it here. I'm not really sure I follow what this dataset is - are you intending this to be added to each replicate perhaps? Then you might do something like this (untested):
DATA WORK.TMP0TempTableAddtnlPredictData;
do _n_ = 1 by 1 until (eof);
SET WORK.APPEND_TABLE(IN=__ORIG) end=eof;
output;
end;
do replicate = 1 to 5;
do n_predict = 1 to nobs_predict;
set WORK.BASE_PREDICT_2 nobs=nobs_predict point=n_predict;
__FLAG=__ORIG;
__DEP=TOP_CREDIT_HABITAT_2017;
if not __FLAG then TOP_CREDIT_HABITAT_2017=.;
output;
end;
end;
stop;
RUN;
This is the complicated way to get 5 copies of that, one for each replicate. But I'm not sure that's actually what you want - does it even have all of the variables you need? Are you sure you didn't mean to MERGE instead of SET?
Separately, I don't understand why you use the SQL step to append the two samples. I'd either do that in the same data step here or I'd use PROC APPEND, both would be faster than the SQL union and then immediately appending more to the dataset.

Nothing happening when running code sas

Does anyone else have this problem? Basically, sometimes when I write a macro and run the code, nothing happens. The log just writes the code you tried to execute in black but it's like SAS is disabled and you have to turn off SAS and turn it back on before it runs properly again. Is there a way around this without having to turn off and on sas.
this is my code:
dm 'clear log';
dm 'clear output';
dm 'odsresults: clear';
libname projet 'C:\Users\MJ-INFO\Desktop\Projet scoring1' ;
/*Extrcation de la base d'etude et creation d'une copie*/
data Examen ;
set projet.base_resiliation_proj ;
run;
/*Contenu de la base*/
proc contents data=Examen;
run;
/*Corespondance entre les formats et les variables */
proc format ;
value $sexe
"1"="homme"
"2"="femme";
run;
/*Applicatation des formats*/
data Examen;
set projet.base_resiliation_proj ;
format sexe $sexe.;
run ;
/*Nous avons 53892 observations et 8 variables dans notre base*/
/*Definition de la variable à expliquer *
%let var_cible=RESIL;
/*Definition des variables explicatives */
%let var_quali=formule sexe;
%let var_quanti=anc_client anc_cont cotisation id nb_cont;
/*Vue sur la variable cible*/
proc freq data=Examen;
table &var_cible;
run;
/*14.42 des contrats sont des fragiles*/
/*Exploration des variables candidates de la base*/
proc freq data=Examen;
table &var_quali;
run;
proc means data=Examen min max mean median nmiss;
var &var_quanti;
run;
/*Traitement des valeurs manquantes/aberrantes*/
data Examen;
set Examen;
if cotisation=-1 then delete;
if cotisation='.' then delete;
if nb_cont=99999 then delete;
run;
/*II.Preparation des donnees*/
/*Etude des liaisons entre variables qualitatives et variable cible */
/*Variables qualitatives : test de Khi-2 & v de Cramer*/
%macro quali(table,var,cible,mod);
/*Representation en terme d'effectif*/
proc gchart data=&table;
vbar3d &var. / sumvar=&cible discrete;
title "Effectifs de la variable &var";
run;
/*Taux de contrat à risque*
proc freq data=&table;
table &var.*&cible / chisq outpct out=pct;
run;
proc gchart data=pct (where=(&cible=&mod));
vbar3d &var. / sumvar=pct_row discrete;
title "Taux de contrats à risque de la variable &var";
run;
quit;
title;
%mend;
%quali(Examen,sexe,&var_cible,1);
Sas show me black execute from running this code:
/*II.Preparation des donnees*/
/*Etude des liaisons entre variables qualitatives et variable cible */
/*Variables qualitatives : test de Khi-2 & v de Cramer*/
%macro quali(table,var,cible,mod);
/*Representation en terme d'effectif*/
proc gchart data=&table;
vbar3d &var. / sumvar=&cible discrete;
title "Effectifs de la variable &var";
run;
I didn't understand why I get black execute even my code has no error when I see the log page ??
Thanks for your help!
Your code:
%macro quali(table,var,cible,mod);
/*Representation en terme d'effectif*/
proc gchart data=&table;
vbar3d &var. / sumvar=&cible discrete;
title "Effectifs de la variable &var";
run;
started to define a macro but never finished. There is no %mend statement at the end, so SAS thinks your still sending it macro code to be compiled. If you add a %mend, it should work.
Most common reasons for SAS feeling non responsive in this way are unclosed macro definition, unclosed comment block, and unmatched quotes. If you google "SAS magic string" you'll find examples of code you can submit to try to recover when you're stuck in this situation. Stuff like:
*';*";*/;%mend;
If you're using Enterprise Guide it automatically adds a magic string every time you submit code. This means you're session won't feel hung. But where you have an unclosed macro definition it can make it harder to recognize,because it looks like everything fan fine. But in reality it didn't execute at all. The magic string can end up hiding the problem. I assume SAS studio also adds a magic string, but I haven't checked.

How to do sub plot using sas

I want to make a simple time series line plot without highlighting any dots on the line. I can plot var1 and var2 using the following code.
title "Title";
proc gplot data=test;
plot var1 *var2 /overlay grid hminor=0 ;
run;
quit;
However I want to add another variable into the plot. I tried the following code. Because the scale of var1 and var3 are quite large, so var3 are not properly scaled in the graph. Can anyone teach me how to use different scale for var1 and var3 please.
title "Title";
proc gplot data=Test;
plot var1 *var2 Var3*var2 /overlay grid hminor=0 ;
run;
quit;
Additionally, may I ask whether sas can do subplot as matlab please. Essentially, I got one big graph with two separate sub-graph. If possible, please teach me how to achieve this. I tried vpercent = 50, but it seems there are something wrong in my code.
proc gplot data=Test vpercent=50;
plot VAR1 *VAR2 VAR3*VAR2 /overlay grid hminor=0 ;
run;
quit;
With Thanks
Assuming I understand what you mean, if you have access to SGPLOT you can specify that X3 should be on a different axis. Here's an example with the SASHELP.STOCKS data which plots the open price on one Y axis and then the trade volume on the second Y axis.
proc sgplot data=sashelp.stocks;
where stock='IBM';
series x=date y=open;
series x=date y=volume/y2axis;
run;quit;
Here is some SAS code that builds on Reeza's excellent example and suggestion to use SGPANEL. See the PANELBY statement and the options used there.
*** SUBSET DATA AND SORT ***;
proc sort data=sashelp.stocks out=ibm;
where stock='IBM';
by date;
run;
*** TRANSPOSE DATA FROM "SHORT-AND-WIDE" TO "LONG-AND-THIN" ***;
proc transpose data=ibm out=ibm_t;
by date;
var open volume;
run;
proc sgpanel data=ibm_t;
*** ROW LATTICE OPTION STACKS PLOTS ***;
*** UNISCALE OPTION LETS EACH PANEL HAVE IT'S OWN SCALE ***;
*** NOVARNAME SUPPRESSES LABEL FOR THE Y-AXIS ON THE RIGHT SIDE ***;
panelby _name_ / layout=rowlattice uniscale=column novarname;
series x=date y=col1;
*** SUPPRESS LABEL FOR THE Y-AXIS ON THE LEFT SIDE ***;
rowaxis display=(nolabel);
run;

SAS PROC PLOT unnecessarily huge chart

This is code for a HW question in my Multivariate Analysis Class
options nodate nonumber;
TITLE 'Problem #1 ';
DATA IRIS;
INFILE '~\iris.txt';
INPUT SL SW PW PL Species;
PROC GLM;
CLASS Species;
MODEL SL SW PW PL = Species;
MANOVA H=SPECIES/PRINTE PRINTH;
RUN;
proc candisc data=IRIS out=ftstat;
CLASS Species;
VAR SL SW PW PL;
TITLE 'Discriminant Analysis for Problem #1';
RUN;
goptions reset=all;
PROC PLOT DATA=ftstat uniform;
PLOT CAN2*CAN1=Species;
RUN;quit;
PROC PLOT is currently generating a huge chart, maybe 5-10 pages tall, with ridiculous vertical scaling (something like .05 = an inch+ of computer screen.) It's too big to put in a word document to hand in, and it's not informative as is.
My question is why is my SAS doing this, and can I fix it? I'd love it to be scaled down to a 5" x 5" or something like that...can I do this? (I've a working knowledge of SAS, but I'm far from skilled at it.)
Try using ods graphics and PROC SGPLOT.
ods graphics on / width=5in height=5in;
PROC SGPLOT DATA=ftstat;
SCATTER can2*can1=species;
run;