Desktop productivity for business analysts and programmers

Import a CSV file from a URL with varying date value

Reply
Occasional Learner
Posts: 1

Import a CSV file from a URL with varying date value

I'm trying to compile unique csv files that are generated daily, and attempting to automate that within EG. The url file path will end in the date with a  format of "7-Jun-2018".

 

I had a thought of possibly prompting the user to select the date they would like to use, and have EG pull that specific day's files. I don't know how to take that user input and translate that to a URL path to grab the files.

 

Is there a way to use a variable piece of data, like the desired date, and insert that into part of the URL file path to get the desired daily file?

 

I'm relatively new to EG, so I know this is a broad question. I'm hoping to get a general direction I should start heading.

Respected Advisor
Posts: 4,702

Re: Import a CSV file from a URL with varying date value

[ Edited ]

@968107

A Prompt allows you to take user input during runtime of a program. 

In the SAS code the prompt name is a SAS Macro variable with the value the user entered/selected.

You can use this SAS Macro variable in your code and it will resolve to the value before the SAS code executes (macro "pre-processing").

 

You don't want to define this in a single EG project as then you'd have to distribute copies of this project to your users which makes this unmanageable. For this reason you should implement such a process with a prompt as a Stored Process (centrally saved on the SAS server side) which then can be called out of EG (or other clients).

 

For above to work you'll have to verify that your site got the license for Stored Processes. If yes then below link should give you a starting point.

http://documentation.sas.com/?docsetId=stpug&docsetTarget=stpugwhatsnew94.htm&docsetVersion=9.4&loca...

Super User
Super User
Posts: 7,946

Re: Import a CSV file from a URL with varying date value

Is definitely possible to generate part of code using a macro variable. That is what they were created to do.

Just create the macro variable with the string of characters you need and replace the hardcoded value with the macro variable reference.  Since a filename (or URL in this case) is normally entered as a string literal, make sure to use double quotes on the outside so that SAS will resolve the macro variable references on the inside.

EG prompts will probably return the value in DATE9 format, but it looks like you need the value in DATE11 format.

%let prompt_value = 01JAN2018 ;
%let for_url = %sysfunc(putn("&prompt_value"d,date11));
.....
filename myurl url "http://....&for_url....." .... ;

You might need to add more code to remove leading zero if that is required. Or change the case of the month.

 

For more support with exactly how to code it you need show exactly what you need to create.

 

Also when dealing with URLs that might already have & characters in it you might find it easier to generate the string using a data step. You can use CALL SYMPUTX() to convert the generated string into a macro variable if you need.

 

Valued Guide
Posts: 560

Re: Import a CSV file from a URL with varying date value

In SAS EG open view>Prompt Manage, You can see at left side. Click add and name your prompt value and then click the next tab for prompt values. Select the following as mentioned in the screenshot. You can give min and max values if you wish. image.png

 Now right click the program you want the prompt and choose properties>Prompts (Added the created prompt here). Now you can see a small question mark for your program image.png

 

In your program you can refresence the prompt as macro variable as follows

%let date_value=%sysfunc(INPUTN(&date, date9.), date11.);
%PUT "https://communities.sas.com/&date_value";

 

 

 

Thanks,
Suryakiran
Ask a Question
Discussion stats
  • 3 replies
  • 150 views
  • 0 likes
  • 4 in conversation