Nothing happening when running code sas - 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.

Related

PRXMATCH in SAS EG don't work in open code

I have this little code in SAS EG open code, it gives me 0 in A and I don't understand why!!!
%let ph=FONDS DE BOURSE;
%LET A=%sysfunc(PRXMATCH("/bourse/i","&ph"));
%put &A;
The result :
%let ph=FONDS DE BOURSE;
%LET A=%sysfunc(PRXMATCH("/bourse/i","&ph"));
SYMBOLGEN: La macro-variable PH est résolue en FONDS DE BOURSE
%put &A;
SYMBOLGEN: La macro-variable A est résolue en 0
0
Please, can you help ?
Thank you!
When using macros, you do not need to use quotation marks for string arguments in functions. Quotation marks are passed exactly as-is to PRXMATCH since the SAS macro facility is designed to process raw text. Remove your quotation marks and it will work as expected.
%let ph=FONDS DE BOURSE;
%LET A=%sysfunc(PRXMATCH(/bourse/i,&ph));
%put &A;
When using a data step, you will need to use quotation marks for the first part of the argument. Unquoted strings are processed as variables.
data test;
ph='FONDS DE BOURSE';
A=PRXMATCH("/bourse/i", ph);
run;

non complete proc boxplot in 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).

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.

SAS Proc Report Title Error

I have an issue where by the do loop creates my reports however the title page where the macro is listed doesn't reflect the correct naming convention each time.
It works for each of the bookmarks in PDF as well as the proc report itself. However the titles don't reflect correctly.
%macro PDF_T2(year=, age= );
proc sql noprint;
select distinct region, bh_type
into :region1 - :region14, :bh_type1 - :bh_type14
from table2_IP
;
quit;
/*%put &region1 &region2;*/
/*%put &bh_type1 &bh_type2;*/
ods escapechar '^';
ods pdf file="C:\PDFS\Table2.pdf" pdftoc=2 style=Custom;
options orientation=landscape missing=' '
topmargin=.25in
bottommargin=.25in
leftmargin=.25in rightmargin=.25in ;
ods proclabel " Inpatient Analysis By Plan ";
%do i=1 %to 4;
TITLE "^{style [JUST= C ]Table 2. Inpatient Utilization By Plan,}";
TITLE2 "^{style [JUST= C ]&&region&i. }" ;
Title3 "^{style [JUST= C ]Adult (21 to 64)}";
Title4 "^{style [JUST= C ]&&bh_type&i. Analysis}" ;
PROC REPORT DATA = Table2_IP contents="&&bh_type&i. Table: Inpatient`enter code here`
I would try making sure that you are using %local macro variables. If you have global macro variables floating around that could cause some surprising results.
I would also turn on MPRINT and look at the log to see what code is being generated. It will show the TITLE statements that the macro is generating.
Titles do not clear themselves, but every time your TITLE statement executes it will clear any existing titles.
I modified your code a bit to work on sashelp.prdsale, and it seems fine:
%macro titletest(dummy);
%local i region1 region2;
proc sql noprint;
select distinct region
into :region1 - :region2
from sashelp.prdsale
;
quit;
%put region1=&region1 region2=&region2;
%do i=1 %to 2;
title1 "Results for &&region&i";
proc print data=sashelp.prdsale;
where region="&&region&i";
run;
title1;
%end;
%mend;
options mprint;
%titletest()

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;