Learning SAS? Welcome to the exclusive online community for all SAS learners.

TRACE option for FCMP Function

Accepted Solution Solved
Reply
Super Contributor
Posts: 332
Accepted Solution

TRACE option for FCMP Function

/** Page: 723 of Seventh Edition of Base SAS Procedures Guide **/
proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

 

I am unable to get the output of the FCMP Function under SAS University Edition 2.7 9.4 M5 as shown on the Guide. The NOTE says "The PROCEDURE FCMP printed Page 1". I am unable to see the Page under LOG or RESULTS.

 

Similar thing happens when I use "FILE PRINT;" inside FCMP Function. The NOTE says same as above. But "Page 1" is nowhere found. Have you found any solution for this?

 

Thanks.

DataSP


Accepted Solutions
Solution
‎07-16-2018 07:08 PM
Super User
Posts: 24,010

Re: TRACE option for FCMP Function

 

Assuming it's Page 763 (not 723) or this reference, I think I see what's happening.

http://documentation.sas.com/?docsetId=proc&docsetTarget=p0urpv7yyzylqsn1g2fycva2bs3n.htm&docsetVers...

 

The output from the TRACE PROCEDURE is not written to the HTML files, which is the default for SAS Studio/SAS UE but to a text file. I think I see it pop up and then disappear which is weird, I'm not sure why or what the fix would be. Probably a question for SAS Tech Support. 

 

Either way, a quick workaround is to write to a ODS LISTING file:

 

 

ods listing file='/folders/myfolders/trace_output.txt';

proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

ods listing close;

 

You can then open the file from the location above in your myfolders or in SAS Studio directly.

If you use the functionality a lot, I'd probably consider writing a wrapper to read the data and output back to HTML directly as well. 

 

 

delete_sas_studio.JPG


@datasp wrote:

Thanks Reeza.

 

The FCMP Code below will perfectly work in University Edition.
This is similar to Data _null_ program in Data Step. The
function study_day is called after the function definition
is done. We don't need Data Step to execute the FCMP Function.

 

I am saying that the output shown in the Guide can't be reproduced by SUE.

 

proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

The expectd output is shown in BASE SAS 9.4 PROCEDURES Guide 7th ed.
at Page: 723 for demonstrating what TRACE does.

The FCMP Procedure
--- Program Execution Starting.
1 1 (20:4) Executing Stmt : ASSIGN start =
1 (20:9) start = 18308
1 2 (21:4) Executing Stmt : ASSIGN today =
1 (21:9) today = 18348
1 3 (22:4) Executing Stmt : ASSIGN sd =
--- Subroutine study_day Execution Starting.
1 1 (15:4) Executing Stmt : FUNCTION
1 2 (16:4) Executing Stmt : ASSIGN n =
1 (16:17) n = (event_date=18348) - (intervention_date=18308) = 40
1 3 (17:4) Executing Stmt : IF
1 (17:10) _temp1 = (n=40) >= 0
1 4 (17:17) Executing Stmt : ASSIGN n =
1 (17:21) n = (n=41) + 1 = 41
1 5 (18:7) Executing Stmt : RETURN _study_day_ =
1 (18:14) _study_day_ = (n=41) = 41
1 6 (19:4) Executing Stmt : ENDSUB
--- Subroutine study_day Execution Finished.
1 (22:16) sd = study_day( start=18308, today=18348 ) = 41
--- Program Execution Finished.

 

View solution in original post


All Replies
Super User
Posts: 24,010

Re: TRACE option for FCMP Function

An FCMP function should be used in a data step, proc SQL or somewhere else. It creates a function but doesn't call it, so your code below creates the function but does nothing else. 

 

What are you trying to do?

What do you expect to happen that's not happening?

 

The full code from the documentation is this. Note the data _null_ step which is where the function is actually used. Post this code in to SAS UE and let us know if that works directly. You won't have access to SASUSER so change that library reference as well to a library you do have write access to.

 

libname demo '/folders/myfolders/';

proc fcmp outlib=demo.funcs.trial;
   function study_day(intervention_date, event_date);
      n=event_date - intervention_date;
         if n >= 0 then
            n=n + 1;
         return(n);
   endsub;
options cmplib=demo.funcs;


data _null_;
   start='15Feb2010'd;
   today='27Mar2010'd;
   sd=study_day(start, today);
   put sd=;
run;

 


@datasp wrote:

/** Page: 723 of Seventh Edition of Base SAS Procedures Guide **/
proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

 

I am unable to get the output of the FCMP Function under SAS University Edition 2.7 9.4 M5 as shown on the Guide. The NOTE says "The PROCEDURE FCMP printed Page 1". I am unable to see the Page under LOG or RESULTS.

 

Similar thing happens when I use "FILE PRINT;" inside FCMP Function. The NOTE says same as above. But "Page 1" is nowhere found. Have you found any solution for this?

 

Thanks.

DataSP


 

Super Contributor
Posts: 332

Re: TRACE option for FCMP Function

Thanks Reeza.

 

The FCMP Code below will perfectly work in University Edition.
This is similar to Data _null_ program in Data Step. The
function study_day is called after the function definition
is done. We don't need Data Step to execute the FCMP Function.

 

I am saying that the output shown in the Guide can't be reproduced by SUE.

 

proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

The expectd output is shown in BASE SAS 9.4 PROCEDURES Guide 7th ed.
at Page: 723 for demonstrating what TRACE does.

The FCMP Procedure
--- Program Execution Starting.
1 1 (20:4) Executing Stmt : ASSIGN start =
1 (20:9) start = 18308
1 2 (21:4) Executing Stmt : ASSIGN today =
1 (21:9) today = 18348
1 3 (22:4) Executing Stmt : ASSIGN sd =
--- Subroutine study_day Execution Starting.
1 1 (15:4) Executing Stmt : FUNCTION
1 2 (16:4) Executing Stmt : ASSIGN n =
1 (16:17) n = (event_date=18348) - (intervention_date=18308) = 40
1 3 (17:4) Executing Stmt : IF
1 (17:10) _temp1 = (n=40) >= 0
1 4 (17:17) Executing Stmt : ASSIGN n =
1 (17:21) n = (n=41) + 1 = 41
1 5 (18:7) Executing Stmt : RETURN _study_day_ =
1 (18:14) _study_day_ = (n=41) = 41
1 6 (19:4) Executing Stmt : ENDSUB
--- Subroutine study_day Execution Finished.
1 (22:16) sd = study_day( start=18308, today=18348 ) = 41
--- Program Execution Finished.
Super User
Posts: 24,010

Re: TRACE option for FCMP Function

Can you link to the online documentation version please, for what you're referring to?

 


@datasp wrote:

Thanks Reeza.

 

The FCMP Code below will perfectly work in University Edition.
This is similar to Data _null_ program in Data Step. The
function study_day is called after the function definition
is done. We don't need Data Step to execute the FCMP Function.

 

I am saying that the output shown in the Guide can't be reproduced by SUE.

 

proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

The expectd output is shown in BASE SAS 9.4 PROCEDURES Guide 7th ed.
at Page: 723 for demonstrating what TRACE does.

The FCMP Procedure
--- Program Execution Starting.
1 1 (20:4) Executing Stmt : ASSIGN start =
1 (20:9) start = 18308
1 2 (21:4) Executing Stmt : ASSIGN today =
1 (21:9) today = 18348
1 3 (22:4) Executing Stmt : ASSIGN sd =
--- Subroutine study_day Execution Starting.
1 1 (15:4) Executing Stmt : FUNCTION
1 2 (16:4) Executing Stmt : ASSIGN n =
1 (16:17) n = (event_date=18348) - (intervention_date=18308) = 40
1 3 (17:4) Executing Stmt : IF
1 (17:10) _temp1 = (n=40) >= 0
1 4 (17:17) Executing Stmt : ASSIGN n =
1 (17:21) n = (n=41) + 1 = 41
1 5 (18:7) Executing Stmt : RETURN _study_day_ =
1 (18:14) _study_day_ = (n=41) = 41
1 6 (19:4) Executing Stmt : ENDSUB
--- Subroutine study_day Execution Finished.
1 (22:16) sd = study_day( start=18308, today=18348 ) = 41
--- Program Execution Finished.

 

Super Contributor
Posts: 332

Re: TRACE option for FCMP Function

I don't know how to link. The Documentation I am referring to is:

 

Base SAS® 9.4 Procedures Guide, Seventh Edition
SAS® Documentation
March 16, 2018

 

Regards,

DataSP

Solution
‎07-16-2018 07:08 PM
Super User
Posts: 24,010

Re: TRACE option for FCMP Function

 

Assuming it's Page 763 (not 723) or this reference, I think I see what's happening.

http://documentation.sas.com/?docsetId=proc&docsetTarget=p0urpv7yyzylqsn1g2fycva2bs3n.htm&docsetVers...

 

The output from the TRACE PROCEDURE is not written to the HTML files, which is the default for SAS Studio/SAS UE but to a text file. I think I see it pop up and then disappear which is weird, I'm not sure why or what the fix would be. Probably a question for SAS Tech Support. 

 

Either way, a quick workaround is to write to a ODS LISTING file:

 

 

ods listing file='/folders/myfolders/trace_output.txt';

proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

ods listing close;

 

You can then open the file from the location above in your myfolders or in SAS Studio directly.

If you use the functionality a lot, I'd probably consider writing a wrapper to read the data and output back to HTML directly as well. 

 

 

delete_sas_studio.JPG


@datasp wrote:

Thanks Reeza.

 

The FCMP Code below will perfectly work in University Edition.
This is similar to Data _null_ program in Data Step. The
function study_day is called after the function definition
is done. We don't need Data Step to execute the FCMP Function.

 

I am saying that the output shown in the Guide can't be reproduced by SUE.

 

proc fcmp outlib=work.funcs.trial TRACE;
function study_day(intervention_date, event_date);
n=event_date - intervention_date;
if n >= 0 then n=n + 1;
return(n);
endsub;
start='15Feb2010'd;
today='27Mar2010'd;
sd=study_day(start, today);
run;

The expectd output is shown in BASE SAS 9.4 PROCEDURES Guide 7th ed.
at Page: 723 for demonstrating what TRACE does.

The FCMP Procedure
--- Program Execution Starting.
1 1 (20:4) Executing Stmt : ASSIGN start =
1 (20:9) start = 18308
1 2 (21:4) Executing Stmt : ASSIGN today =
1 (21:9) today = 18348
1 3 (22:4) Executing Stmt : ASSIGN sd =
--- Subroutine study_day Execution Starting.
1 1 (15:4) Executing Stmt : FUNCTION
1 2 (16:4) Executing Stmt : ASSIGN n =
1 (16:17) n = (event_date=18348) - (intervention_date=18308) = 40
1 3 (17:4) Executing Stmt : IF
1 (17:10) _temp1 = (n=40) >= 0
1 4 (17:17) Executing Stmt : ASSIGN n =
1 (17:21) n = (n=41) + 1 = 41
1 5 (18:7) Executing Stmt : RETURN _study_day_ =
1 (18:14) _study_day_ = (n=41) = 41
1 6 (19:4) Executing Stmt : ENDSUB
--- Subroutine study_day Execution Finished.
1 (22:16) sd = study_day( start=18308, today=18348 ) = 41
--- Program Execution Finished.

 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 203 views
  • 0 likes
  • 2 in conversation