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

The PROC IMPORT was how I finally got the file to read as a table. Nothing else worked to get rid of the commas. I'm on to the next issue now. Remedial help (I am a novice) is appreciated. Thanks.

Kurt_Bremser
Super User

A short look at the file lets you see that you have a character value called country, and a lot of numeric values.

So we first take the first line and copy it to our program editor:

Country,Year,School closures (OxBSG),Workplace Closures (OxBSG),Cancel public events (OxBSG),Restrictions on gatherings (OxBSG),Close public transport (OxBSG),Stay at home requirements (OxBSG),Restrictions on internal movement (OxBSG),International travel controls (OxBSG),Income support (OxBSG),Debt/contract relief (OxBSG),Fiscal measures (OxBSG),International support (OxBSG),Public information campaigns (OxBSG),Testing policy (OxBSG),Contact tracing (OxBSG),Emergency investment in health care (OxBSG),Investment in Vaccines (OxBSG),Facial coverings (OxBSG),Stringency Index (OxBSG),Containment and Health Index (OxBSG)

 

Next, split it into separate lines, remove the commas, and add quotes:

 

"Country"
"Year"
"School closures (OxBSG)"
"Workplace Closures (OxBSG)"
"Cancel public events (OxBSG)"
"Restrictions on gatherings (OxBSG)"
"Close public transport (OxBSG)"
"Stay at home requirements (OxBSG)"
"Restrictions on internal movement (OxBSG)"
"International travel controls (OxBSG)"
"Income support (OxBSG)"
"Debt/contract relief (OxBSG)"
"Fiscal measures (OxBSG)"
"International support (OxBSG)"
"Public information campaigns (OxBSG)"
"Testing policy (OxBSG)"
"Contact tracing (OxBSG)"
"Emergency investment in health care (OxBSG)"
"Investment in Vaccines (OxBSG)"
"Facial coverings (OxBSG)"
"Stringency Index (OxBSG)"
"Containment and Health Index (OxBSG)"

We now have most of a nice LABEL statement; let's find some nice valid SAS names, and make the statement complete:

 

label
  country = "Country"
  year    = "Year"
  sch_cl  = "School closures (OxBSG)"
  wpc_cl  = "Workplace Closures (OxBSG)"
  can_pe  = "Cancel public events (OxBSG)"
  rst_ga  = "Restrictions on gatherings (OxBSG)"
  cl_pt   = "Close public transport (OxBSG)"
  sh_req  = "Stay at home requirements (OxBSG)"
  rst_im  = "Restrictions on internal movement (OxBSG)"
  int_tc  = "International travel controls (OxBSG)"
  inc_sp  = "Income support (OxBSG)"
  dc_rel  = "Debt/contract relief (OxBSG)"
  fis_me  = "Fiscal measures (OxBSG)"
  int_sp  = "International support (OxBSG)"
  pbc_ca  = "Public information campaigns (OxBSG)"
  tes_po  = "Testing policy (OxBSG)"
  con_tr  = "Contact tracing (OxBSG)"
  emg_in  = "Emergency investment in health care (OxBSG)"
  inv_vc  = "Investment in Vaccines (OxBSG)"
  fac_cv  = "Facial coverings (OxBSG)"
  str_in  = "Stringency Index (OxBSG)"
  ch_ind  = "Containment and Health Index (OxBSG)"
;

We now can hold down the alt key, mark only the names, and copy that to an input statement, where we add a character informat for country:

input
  country :$50.
  year   
  sch_cl 
  wpc_cl 
  can_pe 
  rst_ga 
  cl_pt  
  sh_req 
  rst_im 
  int_tc 
  inc_sp 
  dc_rel 
  fis_me 
  int_sp 
  pbc_ca 
  tes_po 
  con_tr 
  emg_in 
  inv_vc 
  fac_cv 
  str_in 
  ch_ind 
;

Now combine that with what we already have, and modify the INFILE statement:

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

data test;
infile in dlm=',' dsd firstobs=2 truncover;
label
  country = "Country"
  year    = "Year"
  sch_cl  = "School closures (OxBSG)"
  wpc_cl  = "Workplace Closures (OxBSG)"
  can_pe  = "Cancel public events (OxBSG)"
  rst_ga  = "Restrictions on gatherings (OxBSG)"
  cl_pt   = "Close public transport (OxBSG)"
  sh_req  = "Stay at home requirements (OxBSG)"
  rst_im  = "Restrictions on internal movement (OxBSG)"
  int_tc  = "International travel controls (OxBSG)"
  inc_sp  = "Income support (OxBSG)"
  dc_rel  = "Debt/contract relief (OxBSG)"
  fis_me  = "Fiscal measures (OxBSG)"
  int_sp  = "International support (OxBSG)"
  pbc_ca  = "Public information campaigns (OxBSG)"
  tes_po  = "Testing policy (OxBSG)"
  con_tr  = "Contact tracing (OxBSG)"
  emg_in  = "Emergency investment in health care (OxBSG)"
  inv_vc  = "Investment in Vaccines (OxBSG)"
  fac_cv  = "Facial coverings (OxBSG)"
  str_in  = "Stringency Index (OxBSG)"
  ch_ind  = "Containment and Health Index (OxBSG)"
;
input
  country :$50.
  year   
  sch_cl 
  wpc_cl 
  can_pe 
  rst_ga 
  cl_pt  
  sh_req 
  rst_im 
  int_tc 
  inc_sp 
  dc_rel 
  fis_me 
  int_sp 
  pbc_ca 
  tes_po 
  con_tr 
  emg_in 
  inv_vc 
  fac_cv 
  str_in 
  ch_ind 
;
run;

Voila, this is the log (run on my University Edition):

 123          ch_ind
 124        ;
 125        run;
 
 NOTE: The infile IN is:
       Filename=https://github.com/owid/covid-19-data/raw/master/public/data/bsg/COVID%20Government%20Response%20(OxBSG).csv,
       Local Host Name=localhost.localdomain,
       Local Host IP addr=::1,
       Service Hostname Name=raw.githubusercontent.com,
       Service IP addr=199.232.16.133,
       Service Name=N/A,Service Portno=443,
       Lrecl=32767,Recfm=Variable
 
 NOTE: 57596 records were read from the infile IN.
       The minimum record length was 28.
       The maximum record length was 134.
 NOTE: The data set WORK.TEST has 57596 observations and 22 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           34.33 seconds
       cpu time            1.33 seconds

and the file imported fine.

As you can see, it took me about a quarter of an hour from reading your post to do this. That's why I never use IMPORT on a CSV file.

SASKiwi
PROC Star

There is a trick to this. Run this:

options source;
PROC IMPORT DATAFILE=COVID1 DBMS=CSV OUT= COVID1;
run;

Then check your SAS log. Do you see DATA step code there? If so do a block copy (hold Alt key and mark code block to copy with mouse, then Ctrl C, Ctrl V) to paste that back into your program editor where you can fine-tune variable lengths etc. Now run your corrected DATA step code instead of PROC IMPORT.

Kurt_Bremser
Super User

My code was only for diagnostic purposes. You can use the file reference in the infile statement and add options like DLM=',' and DSD to read the file as if it was local, with delimited INPUT.

ChrisNZ
Tourmaline | Level 20

Not too sure what you are after, but have looked at the GIT functions, such as GIT_FETCH?

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1803 views
  • 0 likes
  • 5 in conversation