DATA Step, Macro, Functions and more

Proc gplot output shows twice in output

Accepted Solution Solved
Reply
Contributor
Posts: 43
Accepted Solution

Proc gplot output shows twice in output

Below is the code, not sure whats the issue the proc gplot output is showing twice.

 

Also, another question - how to suppress the directory and dataset contents table in the output pdf file.

 

 

*raw data path;
libname seretide "C:/xxxx" INENCODING=ASCIIANY; 

*transformed data path;
libname strans "C:/xxxx" INENCODING=ASCIIANY; 

proc datasets library=work nodetails kill;
/* 	modify have/ correctencoding='utf8'; */
quit;

ods listing close;
ods pdf file="C:\Users\User\0001.pdf" startpage=no;

proc sort data=seretide.en out=entable 
	(drop = subjectstatus visit form formentrydate subjectvisitformid);
	 by subjectid;
run;

proc sort data = seretide.dm out=dmtable 
	(drop = subjectstatus visit form formentrydate subjectvisitformid);
	 by subjectid;
run;

proc sort data=seretide.cm out = cmtable 
	(drop = subjectstatus visit form formentrydate subjectvisitformid);
	 by subjectid;
run;

proc sql noprint;
	create table	work.en_dm_cm as
		select		entable.*, dmtable.*, cmtable.*
		from		work.entable (where = (subjectid = '0001'))
		left join	work.dmtable (where = (subjectid = '0001'))
		on			entable.subjectid = dmtable.subjectid
		left join	work.cmtable (where = (subjectid = '0001'))
		on			entable.subjectid = dmtable.subjectid;
quit; 

data patdemo;
	 set	en_dm_cm;
	 where	subjectid = '0001';
	 label	SCRID = 'Screening Number' 
			SUBJINIT = 'Subject Initials'
			BRTHDTC = 'Date of Birth'
			AGE = 'Age (In Years)'
			RACE = 'Race';
	 if _n_ = 1;
run;


proc print data=patdemo noobs label;
Variables SCRID SUBJINIT SUBJID BRTHDTC AGE SEX ETHNIC RACE;
Title 'Patient Information for 0001';
run;

proc sort data=seretide.ae out=aetable;
	by subjectid;
run;
 
data aetab	 (Keep= SUBJECTID AEYN AESEV AESTDAT AEENDAT AEACN AEOUT);
	 	set   work.aetable;
	 	where subjectid = "0001";
	 	Label AEYN      = 'Adverse Event Yes/No'
	 		  AESEV     = 'Adverse Event Severity'
	 		  AESTDAT   = 'Adverse Event Start Date'
	 		  AEENDAT   = 'Adverse Event End Date'
	 		  AEACN     = 'Action Taken'
	 		  AEOUT     = 'Outcome';
run;
	 	
Proc print data=aetab noobs label;
	Title "No Adverse Events Reported for Patient ID: 0001";
run;

data cmtab;
	 set	work.en_dm_cm 
	 		(keep = subjectid CMYN CMTRT CMTRT_PREFERRED CMTRT_DRUGNAME 
	 		 CMINDC CMSTDAT CMENDAT CMDOSTXT CMDOSU CMDOSUSP CMDOSFRQ
	 		 CMFREQSP CMROUTE CMROUTSP );
	 		 
	 where  subjectid = '0001' and CMYN eq ' ';
	 
	 select;
	 		when (CMDOSU = 'Other') CMDOSU = '(mcg)';
	 		when (CMDOSU = 'Milligram') CMDOSU = '(Mg)';
	 		when (CMDOSU = 'Puff') CMDOSU = '(pf)';
	 		Otherwise CMDOSU = '(IU)';
	 end;
	 
	 if CMDOSFRQ = 'Other' then CMDOSFRQ = CMFREQSP;
	 
	 if CMDOSFRQ ne ' '  then 
	 		DDWF = Strip(CMTRT) || ' ' || strip(CMDOSTXT) || ' ' || strip(CMDOSU) || ' '  || '(' || strip(CMDOSFRQ) || ')';
	 else   DDWF = Strip(CMTRT) || ' ' || strip(CMDOSTXT) || strip(CMDOSU);
	 
	 Label	DDWF = 'Drug Dosage with Frequency';
	 
	 Drop	SUBJECTID CMYN CMTRT CMTRT_PREFERRED CMTRT_DRUGNAME CMDOSTXT CMDOSU
	 	 	CMDOSUSP CMDOSFRQ CMFREQSP CMROUTSP;
	 
run;

proc print data=cmtab noobs label;
	Title 'Concomitant Medication history for Patient ID 0001';
run;

proc sort data=seretide.vs out=vstable;
	by subjectid;
run;

data vstab; 
	set vstable (keep =	SUBJECTID VISIT VSPERF VSDAT VSPOS VSTEST VSORRES 
						VSORRESU VSTEST1 VSORRES1 VSORRESU1);
	where subjectid = '0001';
	
	select;
			when (VSORRESU = 'CM') VSORRESU = '(cm)';
			when (VSORRESU = 'Kg') VSORRESU = '(kg)';
			when (VSORRESU = 'Degree Fahrenheit') VSORRESU = '(°F)';
			when (VSORRESU = 'Beats per Minute') VSORRESU = '(bpm)';
			when (VSORRESU = 'Breaths per Minute') VSORRESU = '(brpm)';
			when (VSORRESU = 'mm Hg') VSORRESU = '(mm Hg)';
			when (VSTEST = 'Height') VSORRESU = '(cm)';
			otherwise VSORRESU = ' ';
	end;
	
	select;
			when (VSORRESU1 = 'CM') VSORRESU1 = '(cm)';
			when (VSORRESU1 = 'Kg') VSORRESU1 = '(kg)';
			when (VSORRESU1 = 'Degree Fahrenheit') VSORRESU1 = '(°F)';
			when (VSORRESU1 = 'Beats per Minute') VSORRESU1 = '(bpm)';
			when (VSORRESU1 = 'Breaths per Minute') VSORRESU1 = '(brpm)';
			when (VSORRESU1 = 'mm Hg') VSORRESU1 = '(mm Hg)';
			otherwise VSORRESU1 = ' ';
	end;
	
	if		Visit =	('Randomization (Visit 2/Day 0)') or 
	  		Visit = ('End of Treatment/Early termination (Visit 3)') then do;
	  		VSTEST = VSTEST1;
	  		VSORRES = VSORRES1;
	  		VSORRESU = VSORRESU1;	
	end;
	
	retain _vsdat _vspos;
	
	if not missing(vsdat) then _vsdat = vsdat;
	else vsdat = _vsdat;
	
	if not missing(vspos) then _vspos = vspos;
	else vspos = _vspos;
	
	if vsperf = 'Yes' then delete;
	
	drop _vsdat _vspos VSPERF VSTEST1 VSORRES1 VSORRESU1 ;
run;


Proc sort data=vstab (where=(vstest ne 'Height')) out=vstab;
by vstest vsdat;
run;

data vsdia vssys vstemp vswt vshr vsresp;
	 set vstab;
	 if vstest = 'Diastolic Blood Pressure' then output vsdia;
	 if vstest = 'Systolic Blood Pressure' then output vssys;
	 if vstest = 'Temperature' then output vstemp;
	 if vstest = 'Weight' then output vswt;
	 if vstest = 'Heart Rate' then output vsresp;
run;

Title 'Vital Stats Diastolic Blood Pressure for Patient ID: 0001';

PROC GPLOT DATA = vsdia;
	SYMBOL1 INTERPOL=JOIN HEIGHT=10pt VALUE=NONE LINE=1 WIDTH=2 CV = _STYLE_;
	Axis1 STYLE=1 WIDTH=1 MINOR=NONE label = ('(Hg mm)');
	Axis2 STYLE=1 WIDTH=1 MINOR=NONE;

	PLOT VSORRES * VSDAT  /
 	VAXIS=AXIS1
	HAXIS=AXIS2
	FRAME;
	
	BY VSTEST;
RUN; 

ods pdf close;
ods listing;

Accepted Solutions
Solution
‎10-13-2017 03:06 PM
Community Manager
Posts: 3,383

Re: Proc gplot output shows twice in output

Running this in EG? Or SAS Studio?

 

Add QUIT; after the RUN; in the PROC GPLOT block.

 

RUN; is required to run it.  Another RUN; before a QUIT will run it again...  And EG/SAS Studio automatically add a RUN/QUIT 1-2 punch to close out open-ended statements.

View solution in original post


All Replies
Super User
Posts: 23,332

Re: Proc gplot output shows twice in output

	BY VSTEST;

 

This will likely cause the multiple plots. Are you sure they're identical?

 

Some suggestions:

  • Move the ODS PDF right above the reporting section. The data management stuff can be before the ODS PDF statement. It helps to keep things organized.
  • BY statements should always be right after the PROC statement (after WHERE, if there is one) to help code legibility
  • Use PROC SGPLOT not GPLOT because it has better quality graphics and is easier to use.

 

Contributor
Posts: 43

Re: Proc gplot output shows twice in output

Removed the by statement as it is not relevant now.

 

But still graph is getting duplicated.

 

Also, where exactly you mean to move the ods pdf line  as per the given code above?

Super User
Posts: 23,332

Re: Proc gplot output shows twice in output

Right before the output starts, so in this case it's before PROC GPLOT. 

 

Contributor
Posts: 43

Re: Proc gplot output shows twice in output

But I need output from first proc print as below:

 

proc print data=patdemo noobs label;
Super User
Posts: 23,332

Re: Proc gplot output shows twice in output

[ Edited ]

Can you move the PROC PRINT?

 

EDIT: This is a style issue, you don't need to make the change. I just find it easier to have my code set up in this manner.

 

Super Contributor
Posts: 320

Re: Proc gplot output shows twice in output

Directory and dataset contents: you mean from `PROC DATASETS`? That's before the `ODS PDF`, so it shouldn't be there... are you sure you're running exactly what you posted here?

Definitely add `QUIT` to the PROC GPLOT, as it needs it. Probably won't cause the problem you're seeing, but it could.

Can you write an example using `SASHELP.CLASS` or similar that still causes this problem (so we can run it and see the problem ourselves)?
Contributor
Posts: 43

Re: Proc gplot output shows twice in output

Posted in reply to snoopy369

snoopy,

 

Reg. directory and datasets: I meant in the result window 2 tables are displayed on top as attached. I don't want that in the output PDF.

 

 

Super Contributor
Posts: 320

Re: Proc gplot output shows twice in output

Krisraa, that is indeed the PROC DATASETS output.

What that means to me is that you are somehow running this twice without closing ODS PDF. I.e., something like this is actually happening:

proc datasets ... ;
quit;
ods pdf file="whatever.pdf";
proc gplot ... ;
run;
...
proc datasets ...;
quit;
ods pdf file="whatever.pdf";
proc gplot ... ;
run;

ods pdf close;

I'm sure that's not what you intended.  The ODS PDF CLOSE; is not happening after the first run, for whatever reason.  

 

Solution
‎10-13-2017 03:06 PM
Community Manager
Posts: 3,383

Re: Proc gplot output shows twice in output

Running this in EG? Or SAS Studio?

 

Add QUIT; after the RUN; in the PROC GPLOT block.

 

RUN; is required to run it.  Another RUN; before a QUIT will run it again...  And EG/SAS Studio automatically add a RUN/QUIT 1-2 punch to close out open-ended statements.

Contributor
Posts: 43

Re: Proc gplot output shows twice in output

[ Edited ]
Posted in reply to ChrisHemedinger

Chris,

 

Thanks! yes adding quit; resolved it.

 

Using SAS Studio 3.5

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 342 views
  • 12 likes
  • 4 in conversation