BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

Is there a good article on how to export a SAS dataset you have in a stored process to a datalines statement.  I want to take a dataset I have in a stored process and share it in a forum post.

1 ACCEPTED SOLUTION
16 REPLIES 16
Reeza
Super User

Why yes there is 😀 

 

http://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

 

Also, if you're on EG there's a custom task that can be used - see Chris Hemedingers blog. 

 

 

DavidPhillips2
Rhodochrosite | Level 12

Which post is it in his blog?

 

General blog link:

http://blogs.sas.com/content/sasdummy/author/chrishemedinger/page/4/

DavidPhillips2
Rhodochrosite | Level 12

Reeza,

 

When I tried to run the macro in the blog http://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/ I was unable to get it to work. How do you use this Marco?  I copied it to Enterprise Guide and tried passing parameters.

Reeza
Super User

I wrote a post about how to do it using SAS UE

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

I'm assuming you have a dataset somewhere that you'd like to create the dataset for?

 

You would open the data2datastep.sas macro and run that.

Then call the macro, The third parameter is the name and path of the file that gets created. You'll have to specify that for your system. 

Something like the following I imagine:

 

%data2datastep(cars,sashelp,C:\temp\out.sas,5)

 

It probably depends a bit on your set up, if you're on a server for instance it might be different. 

DavidPhillips2
Rhodochrosite | Level 12

I've got a server setup:

 

ERROR: Insufficient authorization to access /sasconfig/Lev1/SASApp/C:\temp\out.sas.

Reeza
Super User

Yeah, unfortunately you'll need a place to be able to create the file on the server. What happens if you leave the third parameter blank?

 

I'll take a look at the macro later and see if there's a way to output it to a dataset or log that could then be copied to avoid this issue. 

 

I've only perused the code so far, so not sure if that's even possible.

 

I assume you weren't able to install the add in?

DavidPhillips2
Rhodochrosite | Level 12

I found a location to save the output to that works for me.

 

Is the add on safe?  It looks like an install file from an unknown vendor.

 

I’m trying to modify the code to allow me to output an active dataset so that I can narrow down the dataset before outputting it.  But understanding the code is tricky.  

 

If I could replace this section:

 

from dictionary.columns
where libname="&lib"
and memname="&dsn"

 

with something like:

 

from work.mytable

Reeza
Super User

What do you mean by narrow down the dataset?

Wouldn't you subset the table and then pass that to the macro?

 

data sub;

set have;

where <limit>;

run;

 

%data2datastep(sub, work, ,20);

 

The part of the code you're currently viewing would provide the column names and data types. I'm not sure that referencing your table would make sense. 

 

The add on is safe, it's published by SAS, @ChrisHemedinger

I found that I needed IT Admin rights to unlock it though.

 

 

DavidPhillips2
Rhodochrosite | Level 12

Reeza, 

 

That works.  I wasn't sure how to reference the work library like that. 

 

Thanks for your help on this.

DavidPhillips2
Rhodochrosite | Level 12

I put 10000 in for obs but my output is cut off at about 2000 rows.  My dataset only has 4 columns so its not huge.

Reeza
Super User

There's no limit in the code that I can see that would restrict it to 2000 records...when you run the code, it only creates 2000 observations?

DavidPhillips2
Rhodochrosite | Level 12

It creates 2321 records and cuts off on the last record.  I think it is some sort of length issue. 

 

I'm looking at how to install the plugin.

Reeza
Super User

This works for me. Does it truncate for you as well?

 

data random;
do i=1 to 10000;
x=1;
y=x*2;
z=rand('normal', 25, 5);
w=floor(y*z);
output;
end;
run;


%data2datastep(random,work,C:\_localdata\out.sas,10000)

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 16 replies
  • 2612 views
  • 5 likes
  • 2 in conversation