<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Importing an excel file from world bank with all data in a single column. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644833#M78494</link>
    <description>&lt;P&gt;Don't bother with proc import, write the data step yourself. You have country name, country code, two redundant columns you can drop anyway, and then numeric columns for 1960-2019. And the data starts in line 6, with line 5 holding the header, which might be hard for proc import to catch.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile "......csv" dlm=',' dsd truncover firstobs=6;
input country_name :$40. country_code :$3. dummy :$1. dummy (_1960-_2019) (:20.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 03 May 2020 13:32:20 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-03T13:32:20Z</dc:date>
    <item>
      <title>Importing an excel file from world bank with all data in a single column.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644832#M78493</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;I was trying to import a CSV file with CPI data from World Bank, from here:&amp;nbsp;&lt;A href="https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG" target="_blank" rel="noopener"&gt;https://data.worldbank.org/indicator/FP.CPI.TOTL.ZG&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and importing a file named 'API_FP.CPI.TOTL.ZG_DS2_en_csv_v2_988671.csv'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I reckon is that there are few delimiters, including space, tab and comma.&lt;/P&gt;&lt;P&gt;Whatever I specify in a delimiter option I never get the expecting results. For instance:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile="/home/sasuser.v94/pliki/API_FP.CPI.TOTL.ZG_DS2_en_csv_v2_988671.csv"
        out=inflation_wb
        dbms=dlm
        replace;
        delimiter=' ,"';
        getnames=no;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I will recieve an output with 74 columns and no data.&lt;/P&gt;&lt;P&gt;When I specify delimiter=' ,'; then I will get the ouput with all data packed in one column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone knows by any chance, how can I import this csv and get it properly displayed?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 13:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644832#M78493</guid>
      <dc:creator>nowak22</dc:creator>
      <dc:date>2020-05-03T13:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an excel file from world bank with all data in a single column.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644833#M78494</link>
      <description>&lt;P&gt;Don't bother with proc import, write the data step yourself. You have country name, country code, two redundant columns you can drop anyway, and then numeric columns for 1960-2019. And the data starts in line 6, with line 5 holding the header, which might be hard for proc import to catch.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile "......csv" dlm=',' dsd truncover firstobs=6;
input country_name :$40. country_code :$3. dummy :$1. dummy (_1960-_2019) (:20.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 May 2020 13:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644833#M78494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-03T13:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an excel file from world bank with all data in a single column.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644836#M78495</link>
      <description>&lt;P&gt;And this would be my final code to create a proper dataset with minimal use of space and an intelligent structure for further processing (code is tested on University Edition):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wide;
infile "/folders/myfolders/API_FP.CPI.TOTL.ZG_DS2_en_csv_v2_988671.csv" dlm=',' dsd truncover firstobs=6;
input country_name :$40. country_code :$3. dummy :$1. dummy (_1960-_2019) (:20.);
drop dummy;
run;

proc sort data=wide;
by country_code;
run;

proc transpose data=wide out=long (rename=(col1=income) where=(income ne .));
by country_code;
var _:;
run;

data cntlin;
set wide (
  keep=country_code country_name
  rename=(country_code=start country_name=label)
);
retain fmtname "country" type "C";
run;

proc format cntlin=cntlin;
run;

data want;
set long;
year = input(substr(_name_,2),4.);
format country_code $country.;
drop _name_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 14:16:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644836#M78495</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-03T14:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an excel file from world bank with all data in a single column.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644844#M78496</link>
      <description>&lt;P&gt;Thank you kind Sir, I will have to work on your code then to fully understand it.&lt;/P&gt;</description>
      <pubDate>Sun, 03 May 2020 14:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/644844#M78496</guid>
      <dc:creator>nowak22</dc:creator>
      <dc:date>2020-05-03T14:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Importing an excel file from world bank with all data in a single column.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/645013#M78509</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319804"&gt;@nowak22&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you kind Sir, I will have to work on your code then to fully understand it.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The first step reads the file into a dataset; to make it easier to code, I used a variable list (_1960-_2019), which creates all variables in the sequence automatically.&lt;/P&gt;
&lt;P&gt;Next, I sorted this dataset to facilitate the use of BY in the transpose step.&lt;/P&gt;
&lt;P&gt;The transpose converts the horizontal structure to a vertical structure, removes the country name, and removes all missing values by means of a WHERE= dataset option.&lt;/P&gt;
&lt;P&gt;Then I extract the country code and country name and rename them, add the necessary variables for a "controlin" dataset for PROC FORMAT, and execute PROC FORMAT to create a format that maps from country code to country name.&lt;/P&gt;
&lt;P&gt;In the final step, I ceate a numeric YEAR variable from the variable _NAME_, which was automatically created in the transpose step. In this step, I also use the newly created format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the resulting dataset is to be used later, you should add the format to a permanent format catalog that is in your FMTSEARCH system option.&lt;/P&gt;</description>
      <pubDate>Mon, 04 May 2020 15:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Importing-an-excel-file-from-world-bank-with-all-data-in-a/m-p/645013#M78509</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-04T15:01:54Z</dc:date>
    </item>
  </channel>
</rss>

