Desktop productivity for business analysts and programmers

Code for exporting as a step in process

Reply
New Contributor
Posts: 3

Code for exporting as a step in process

I'm using EG version 7.13

At the end of a process, I want to export the results as a step in the process. The file should end up on my computer as an Excel file.

I would like to use a prompt to set the name of the exported file, for example "Data from 2017-03", where 2017-03 was entered in my prompt.

How do I do this?

Esteemed Advisor
Esteemed Advisor
Posts: 7,253

Re: Code for exporting as a step in process

I don't use EG so not sure about the exact terminology, but prompts create macro variables do they not?  If so, and you just want a plain Excel file then:

proc export data=abc outtfile="C:\documents\&macro_variable.";
run;

Obviously paths and such like would need to set to your environment and the data= would need to be changed, and if you want nicer output switch to ods tagsets.excelxp.

Valued Guide
Posts: 505

Re: Code for exporting as a step in process

Using a pop up window to enter a dataset name to export to excel

If you get an error running this, contact your IT department and show them the error and
ask them to explain why your code did not work? Link back to this message https://goo.gl/frqxyy https://communities.sas.com/t5/SAS-Enterprise-Guide/Code-for-exporting-as-a-step-in-process/m-p/346954 HAVE (a dataset I want ro export to excel) SASHELP.CLASS WANT (enter the dataset name in a pop up window and export to excel) +----------------------------------------------+ |COMMAND ===> | +----------------------------------------------+ | | | ENTER DATASET NAME __sahelp.class<ENTER>__ | | | +----------------------------------------------+ d:/xls/class_dosubl.xlsx (19 obs) +------+-----------+------+------+ | | A | B | C | +------+-----------+------+------+ | | | | | | 1 | NAME | AGE| SEX | | 2 | Alfred | 14 | M | | 3 | Alice | 13 | F | | 4 | Barbara | 13 | F | | 5 | Carol | 14 | F | | 6 | Henry | 14 | M | | ... | ... | ... | ... | +------------------+------+------+ [CLASS} WORKING CODE window chose irow=5 rows=25 #5 @12 "Enter DSN " dsn $32. attr=underline; display chose; libname xel "d:/xls/class.xlsx"; data xel.class_dosubl; * _ _ _ ___ ___ | |_ _| |_(_) ___ _ __ / __|/ _ \| | | | | __| |/ _ \| '_ \ \__ \ (_) | | |_| | |_| | (_) | | | | |___/\___/|_|\__,_|\__|_|\___/|_| |_| ; * note you can pull these dosubl's out but This seems more flexible to me. 1. Save as one stored program or view? (untested) 2. Could sandwhich a set statement between the two dosubls 3. Could easily iterate either dosubl? 4. This encapsulates the code in one address space(depends on how sas compiles dosubl - but this is the most powerful implementation) data _null_; rc=dosubl(' data _null_; window chose irow=5 rows=25 #5 @12 "Enter DSN " dsn $32. attr=underline; display chose; call symputx("dsn",dsn); stop; run;quit; '); rc=dosubl(' libname xel "d:/xls/class.xlsx"; data xel.class_dosubl; set &dsn (keep=name sex age); run;quit; libname xel clear; '); stop; run;quit;
Respected Advisor
Posts: 3,068

Re: Code for exporting as a step in process

Nice solution @rogerjdeangelis. Unfortunately the OP uses EG where WINDOW statements don't work as SAS runs either remotely or in a separate local session. Prompts are the EG alternative.

Ask a Question
Discussion stats
  • 3 replies
  • 168 views
  • 0 likes
  • 4 in conversation