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.
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
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.
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.
Thanks for your help!
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;
Thanks - I now have the file uploaded but the readout is still CSV. How do I change it to a table format?
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.
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:
Why does it no longer work? Thanks-
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?
Oh - duh. Thanks.
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;
Don't use PROC IMPORT for CSV files, it's not necessary. Write thaedata step yourself, according to the documentation of the CSV file. No need to put up with the guessing of IMPORT.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.