BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

The git interface in SAS Studio or Enterprise Guide (and the GIT_ functions) is for programs, but you are asking about a data file here.

 

For this, you can use FILENAME URL:

filename in url 'https://github.com/owid/covid-19-data/raw/master/public/data/bsg/COVID%20Government%20Response%20(OxBSG).csv';

data test;
length line $100;
infile in truncover;
input line $100.;
run;

Note that I first navigated to the link you posted, and then copied the link of the "Download" button there.

View solution in original post

19 REPLIES 19
SASJedi
SAS Super FREQ

Not sure what you are trying to accomplish here. If you want to use GitHub in the usual way for versioning files, you should use the GUI interface available in SAS Studio or Enterprise Guide, or the SAS functions designed for that to manage that. If you just want to access a file directly in a SAS program, that can be done. For example, I have a bunch of  SAS macro code I share on GitHub. Say you wanted to use my DATA2DATASTEP macro. The macro takes an existing data set and creates a DATA program that will re-create the dataset when executed. (Great for sharing a bit of data with your code when asking questions here on SAS Communities 😁) The shared macros are stored at https://github.com/SASJedi/sas-macros. To use a file from the Internet in your code, you'll want the RAW version, not the HTML. By clicking around on GitHub, you can find the URL for the raw file (https://raw.githubusercontent.com/SASJedi/sas-macros/master/data2datastep.sas)   Now to run that file as code in my SAS session:

/* Point a fileref to the RAW github file */
filename mycode url "https://raw.githubusercontent.com/SASJedi/sas-macros/master/data2datastep.sas";
/* Use %INCLUDE to run the code in your SAS session */
%include mycode;

/* Test the macro */
%data2datastep(?)

The test of the macro will yield syntax help in the SAS log:

 

 NOTE: DATA2DATASTEP macro help document:
       Purpose: Converts a data set to a SAS DATA step.
       Syntax: %DATA2DATASTEP(dsn<,lib,outlib,file,obs,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: LIBREF for the output dataset. (Optional - default is WORK)
       file:   Fully qualified filename for the DATA step code produced. (Optional)
               Default is create_&outlib._&dsn._data.sas in the SAS default directory.
       obs:    Max observations to include the created dataset.
               (Optional) Default is MAX (all observations)
       fmt:    Format the numeric variables in the output dataset like the original data set?
               (YES|NO - Optional) Default is YES
       lbl:    Reproduce column labels in the output dataset?
               (YES|NO - Optional) Default is YES

 

May the SAS be with you!
Mark

Check out my Jedi SAS Tricks for SAS Users
Newtrix
Calcite | Level 5

Thanks for responding. Not sure I'm doing anything quite so involved. Pretty much a rank novice at this point. All I'm trying to do is to upload a CSV file from a GitHub location onto SAS Studio (using University Edition) so I can poke around and have a look. File location is https://github.com/owid/covid-19-data/blob/master/public/data/bsg/COVID%20Government%20Response%20(O....

 

I appreciate your help. Thanks again.

Kurt_Bremser
Super User

The git interface in SAS Studio or Enterprise Guide (and the GIT_ functions) is for programs, but you are asking about a data file here.

 

For this, you can use FILENAME URL:

filename in url 'https://github.com/owid/covid-19-data/raw/master/public/data/bsg/COVID%20Government%20Response%20(OxBSG).csv';

data test;
length line $100;
infile in truncover;
input line $100.;
run;

Note that I first navigated to the link you posted, and then copied the link of the "Download" button there.

Newtrix
Calcite | Level 5

I added a line to the code which I thought would take care of it but it didn't work:

 

FILENAME in url 'https://github.com/owid/covid-19-data/raw/master/public/data/bsg/COVID%20Government%20Response%20(Ox...';

data COVID1;
length line $100;
infile in truncover DLM=',';
input line $100.;
run;

proc print data=covid1 (OBS=100);
run;

Newtrix
Calcite | Level 5

Thanks - I now have the file uploaded but the readout is still CSV. How do I change it to a table format?

ChrisNZ
Tourmaline | Level 20
Use proc import to create the skeleton data step code, and alter it to ensure it reads the data as desired.
Newtrix
Calcite | Level 5

Thanks - that worked. Next step - nothing seems to be working as the book tells me it will - is to extract US records from the dataset. 

 

Code so far:

FILENAME COVID1 url 'https://github.com/owid/covid-19-data/raw/master/public/data/bsg/COVID%20Government%20Response%20(Ox...';
PROC IMPORT DATAFILE=in DBMS=CSV OUT= COVID1;

DATA COVID1US1;
SET COVID1;
IF COUNTRY = "United States";
RUN;

 

Log says that "57409 observations read" from the original file, and that the new data file was created, but has "0 observations and 22 variables." 
Thanks in advance for your patience and expertise.

ChrisNZ
Tourmaline | Level 20
Your where clause is wrong then. Do a proc freq on country to see the values.
Newtrix
Calcite | Level 5

Ok, new issue. Before I could get the subset straightened out, I had to re-upload the file. I should mention that I'm running on UE. The code and log: 

 

73 FILENAME COVID1 url
74 PROC IMPORT DATAFILE=in DBMS=CSV OUT= COVID1;
75 RUN;
 
NOTE: Unable to open parameter catalog: SASUSER.PARMS.PARMS.SLIST in update mode. Temporary parameter values will be saved to
WORK.PARMS.PARMS.SLIST.

 

ERROR: Physical file does not exist, /opt/sasinside/SASConfig/Lev1/SASApp/IN.
ERROR: Import unsuccessful. See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.

 

Why does it no longer work? Thanks-

SASKiwi
PROC Star

The way you have written this you are trying to read in a CSV file called IN from your current SAS session directory: /opt/sasinside/SASConfig/Lev1/SASApp

Then you are trying to write this out to GITHUB. The file IN does not exist. What are you actually intending to do? 

Newtrix
Calcite | Level 5

Thanks, that was helpful. Now 2 issues - 1) need to increase a variable length 2) need to extract "United States" WITHOUT including "United States Virgin Islands".

Code so far, which did nothing for the length - still truncated at 11. Tried to get it as early in the DATA statement as SAS would accept it but no dice:

FILENAME COVID1 url 'https://github.com/owid/covid-19-data/raw/master/public/data/bsg/COVID%20Government%20Response%20(OxBSG).csv';
PROC IMPORT DATAFILE=COVID1 DBMS=CSV OUT= COVID1;
DATA COVID1;
LENGTH Country $25;
SET COVID1;
RUN;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 19 replies
  • 1156 views
  • 0 likes
  • 5 in conversation