The SAS Output Delivery System and reporting techniques

Dynamic Creation of SAS Program File

Reply
Occasional Contributor
Posts: 18

Dynamic Creation of SAS Program File

I am stuck and I am hoping one of the many SAS guru can assist me. I am trying to dymanically generate several .sas files that are incrementally named (e.g. PRG01.SAS, PRG02.SAS, etc.) and each of which contains slightly different contents (e.g. PRG01.SAS contains Data WORK.TMP01; Set MYTBL (FirstObs=1 OBS=1000000); run; and PRG02.SAS contains Data WORK.TMP01; Set MYTBL (FirstObs=10000001 OBS=2000000); runSmiley Wink

The FIRSTOBS and OBS values are calculated based on a macro variable value that I compute in two prior DATA STEPs using a CALL SYMPUT. I then attempt to pass those values to my macro (which is were I think the breakdown is occuring) which it uses to calcute the FIRSTOBS and OBS values for each iteration of a %DO loop. Inside the loop, I am also opening the ODS buffer to spool off statement to the dynamically named .SAS files mentioned above.

Any ideas on what I am doing wrong?
Super Contributor
Super Contributor
Posts: 3,174

Re: Dynamic Creation of SAS Program File

Posted in reply to Michael_W
Suggest you share some code and explain exactly what error (or undesirable result) you are getting. When deriving SYMPUT, there are resolution issues that can occur, so you always want to end each DATA (and PROC for my own opinion) with a RUN; statement, so SAS performs the compilation up to the current point in the code execution, even within a macro.

Also, consider writing a general purpose (as in one resuable) macro and re-execute it as needed passing any necessary parameters.

Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 18

Re: Dynamic Creation of SAS Program File

Thanks Scott. Great suggestion. I will definitely keep that in mind down the road. Shortly after posting my issue, I figured out what my problem was (I was using single quotes when I should have used double quotes). That simple oversight ultimately did the trick! Thanks for responding so quickly.
Ask a Question
Discussion stats
  • 2 replies
  • 132 views
  • 0 likes
  • 2 in conversation