BookmarkSubscribeRSS Feed
Quentin
Super User

I'd say someone at SAS should just slip data2datastep.sas into default autocall library installed during the build of the next maintenance release.  Even if you call it pre-release or experimental or whatever.  Of course it will be years until 50% of SAS users are on that release, but I think it would pay off in the long run.

 

Idea of downloading via URL is nice, but many folks working on servers (or even PC's) behind firewalls my not have access to the web.

 

I will admit that I don't use this macro enough myself.  I often end up typing a little CARDS data step by hand, and I'm surprisingly bad at that, even after 20 years...

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
FreelanceReinh
Jade | Level 19

Thanks, @Quentin. I agree that %data2datastep would be a valuable addition to the default autocall library. After all, its applications are not limited to supporting the creation of sample data.

 

Good point that some people's web access is restricted. I have no idea how many members of our target audience would be affected. Some of them might not be allowed to publicly share information about their work anyway.

PaigeMiller
Diamond | Level 26

@FreelanceReinh wrote:

Thanks a lot, @PaigeMiller. I'm not too optimistic either. Still, improvements to the user experience are always a good thing.

 

I understand your frustration with all these imprecise problem descriptions. Apparently, there is a correlation between the ability to describe a problem accurately and the ability to solve this problem.

 

Would it help to add (mandatory) checkboxes or drop-down lists (for SAS version etc.) to the "New Message" field?


Yes, I'm sure it would help some, just like when you submit a ticket to SAS tech support, you have to specify operating system and version of SAS and a few other things. You can't submit the ticket without that information. And it ought to be configured so that if a user submits this information once in the SAS communities, it is remembered for the future until the user changes it. 

 

But there are other information needed that won't fit into checkboxes or dropdown lists. I suppose you could enforce somehow that all data must be in the form of a SAS data step, or pre-defined SAS data set (like SASHELP.CLASS), but then you get into the territory where users will be unhappy that they just can't ask a simple question without all of these intrusive requirements, and I don't think that's good. 

--
Paige Miller
SASJedi
SAS Super FREQ

Wow - you guys are REALLY thinking about how to make this easy for a new user!  Thanks for all the thought put into this. I'm working on a new post with a slightly modified version of the macro to make it easier to use right out of the box. I've stolen prolifically from the suggestions here.  The idea of hosting the program file on http so that it was directly accessible was brilliant. I have a prototype up right now for testing.  Feel free to test and comment, but please don't formalize this - the URL will probably change when this goes live. Here's the code a new user would run to get set up:

filename _d2d url 'http://blogs.sas.com/content/sastraining/files/2018/08/data2datastep.txt' debug; 
filename _prg temp;

data _null_;
   infile _d2d;
   file _prg;
   input;
   put _infile_;
run;

%include _prg;
filename _d2d;
filename _prg;

%data2datastep(!HELP)

This produces the docs in the SAS log, but I've moved the "getting started quickly" help to the top, and the detailed syntax help to the bottom like this:

NOTE: DATA2DATASTEP macro help document:

      Purpose: Writes a SAS DATA step program to re-create a SAS data set.

        Example - To create a SAS program to reproduce 10 rows of the dataset SASHELP.CARS,
                  writing the copy to the SAS WORK library (WORK.CARS), just run this code:

         %DATA2DATASTEP(CARS,SASHELP,WORK,10)


NOTE:  Use %DATA2DATASTEP(!HELP) to print this detailed help for this macro.

      Syntax: %DATA2DATASTEP(dsn<,lib,outlib,obs,file,fmt,lbl>)

      dsn:    Name of the dataset to be converted. Required.
      lib:    LIBREF of the original dataset. (Optional - if DSN is not fully qualified)
      outlib: (Optional) LIBREF for the output dataset. Default is WORK
      obs:    (Optional) Max observations to include the created dataset.
                Default is MAX (all observations)
      file:   (Optional) Fully qualified filename for the DATA step code produced.
                Default is create_&outlib._&dsn._data.sas in the SAS default directory:
                S:\Workshop
      fmt:    (Optional) Format the numeric variables like the original data set?
                (YES|NO) Default is YES
      lbl:    (Optional) Reproduce column labels in the output dataset?
                (YES|NO) Default is YES

Another minor mod is that, when finished creating code, the macro now reports where to find the program it created. For example, running this code:

%DATA2DATASTEP(CARS,SASHELP,WORK,10)

produces this response in the SAS log:

      *****************************************************************
       Your SAS program which creates WORK.CARS is ready at
       S:\Workshop/create_WORK_CARS_data.sas
      *****************************************************************

 

I've tested this and it works in SAS University Edition, PC SAS and in SAS Enterprise Guide. 

I'm eager to hear your thoughts and comments on how to make this better and simpler for the new user.

Check out my Jedi SAS Tricks for SAS Users
BeverlyBrown
Community Manager

@SASJedi, thanks for jumping on this thread and pulling these great ideas into a post! Write it as a library article and select the New SAS User label that I just created. That'll make it easy for me to steward and share this type of content later. Appreciate everyone sharing their POVs. 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
art297
Opal | Level 21

@SASJedi: Unfortunately, I'm not familiar with github but, from reading some posts, one apparently can upload a file there and have it saved as a RAW file, and such a file can be directly imported into SAS.

 

Hopefully, someone who is familiar with github can explain what one has to do in order to use the raw url.

 

e.g., there is one at: https://raw.githubusercontent.com/SchmidtPaul/HeritabilityScripts/master/SAS/MACRO%20H2_Piepho.sas

 

with it, I think one can use:

filename h2 url "https://raw.githubusercontent.com/SchmidtPaul/HeritabilityScripts/master/SAS/MACRO%20H2_Piepho.sas";
%include h2;

 

and then simply call the macro

 

Art, CEO, AnalystFinder.com

 

Tom
Super User Tom
Super User

Try this:

filename ds2post url 'https://raw.githubusercontent.com/sasutils/macros/master/ds2post.sas';
%include ds2post ;
%ds2post(sashelp.class);
art297
Opal | Level 21

@Tom: Precisely what I was asking about. And, a nice addition to your macro would be a named parameter (anonymize) that would expect a space delimited list of any variable names whose values should be anonymized.

 

e.g.: %ds2post(sashelp.class,anonymize=name)

 

Art, CEO, AnalystFinder.com

 

Tom
Super User Tom
Super User
Anonymizing data is a pretty complicated process. Best would be to run that as a separate macro and produce the new dataset to export.
FreelanceReinh
Jade | Level 19

@Tom wrote:

Try this:

filename ds2post url 'https://raw.githubusercontent.com/sasutils/macros/master/ds2post.sas';
%include ds2post ;
%ds2post(sashelp.class);

This would be very elegant, but for me (SAS 9.4 TS1M2, Windows 7) this technique works only with URLs not using SSL (such as my own website). With the above URL and similarly with SASJedi's "http://blogs.sas.com/..." I get:

ERROR: Cannot load SSL support.
ERROR: Cannot open %INCLUDE file DS2POST.
ERROR: %INCLUDE has encountered an I/O/ error. Canceling submitted statements.
NOTE: The SAS System stopped processing due to receiving a CANCEL request.

UPDATE: It seems that I had not selected the component "SAS/SECURE SSL" when I installed SAS in 2015, hence the error. Following the instructions in http://support.sas.com/kb/57/595.html I could probably install it now, but I decided not to.

Tom
Super User Tom
Super User

@FreelanceReinh wrote:

@Tom wrote:

Try this:

filename ds2post url 'https://raw.githubusercontent.com/sasutils/macros/master/ds2post.sas';
%include ds2post ;
%ds2post(sashelp.class);

This would be very elegant, but for me (SAS 9.4 TS1M2, Windows 7) this technique works only with URLs not using SSL (such as my own website). With the above URL and similarly with SASJedi's "http://blogs.sas.com/..." I get:

ERROR: Cannot load SSL support.
ERROR: Cannot open %INCLUDE file DS2POST.
ERROR: %INCLUDE has encountered an I/O/ error. Canceling submitted statements.
NOTE: The SAS System stopped processing due to receiving a CANCEL request.

UPDATE: It seems that I had not selected the component "SAS/SECURE SSL" when I installed SAS in 2015, hence the error. Following the instructions in http://support.sas.com/kb/57/595.html I could probably install it now, but I decided not to.


You don't need to use HTTS for GitHub.  I think it just copied as HTTPS because I was logged in when I copied the URL.

FreelanceReinh
Jade | Level 19

@Tom wrote: You don't need to use HTTS for GitHub.  I think it just copied as HTTPS because I was logged in when I copied the URL.

Do you mean I should just type filename ds2post url 'http://...'? This doesn't work either (as it didn't with SASJedi's website; same error messages). Using the DEBUG option of the FILENAME statement the log contains the note

NOTE: <<< Location: https://raw.githubusercontent.com/sasutils/macros/master/ds2post.sas

So, it seems that the "s" is automatically inserted in these cases regardless of the call.

art297
Opal | Level 21

@Tom and @FreelanceReinh: But I'd guess that most folks, especially new users, wouldn't run into that problem. And, of course, the code could be housed both ways, and the instructions provided for loading and preparing the macro using the data step that was mentioned earlier. However, to get back to @FreelanceReinh's original comment, I'd bet that more people would take advantage of the macro if it were provided as discussed. I didn't even realized that the original post had a zip file attached, and created the macro by copying and pasting the various sections as shown in the paper/blog.

 

Of course, I agree that including it as a task within SAS would be even better but, in the meantime, I think that the two-method %include url schemes and using the community menu to publicize them, would get more people to use them.

 

Art, CEO, AnalystFinder.com

SASJedi
SAS Super FREQ

I tested this using a RAW URL (from my personal GITHUB project) and it took almost 2.5 minutes to execute vs. 1.9 seconds when served from a traditional web service. I'm serving it right now from blogs.sas.com (I have access to post there). We can probably find a way of uploading the file right here at communities.sas.com - that would probably be best.  I'll check around..

Check out my Jedi SAS Tricks for SAS Users

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Discussion stats
  • 42 replies
  • 5001 views
  • 36 likes
  • 9 in conversation