Write and run SAS programs in your web browser

raw data fetching

Accepted Solution Solved
Reply
Contributor
Posts: 25
Accepted Solution

raw data fetching

  1. “Client_ID_12_months_bill.txt” contains the 12 months credit card bill against each client_id in single Import the data into SAS such that bill for each month is recorded as a separate observation and month number is also specific (Bonus question – Month name instead of month number)
  2. Import “Client_ID_12_months_bill(missing).txt” into SAS considering that there are churners in the data who left the company at different points of time during the year.

 

Data :-  

102563           $167.00  $125.00  $976.00  $483.00  $517.00  $797.00  $879.00  $988.00  $910.00  $451.00  $468.00  $236.00

 

Kindly help :-

my code :- 

 

data      Bill_Summary;
infile      '/folders/myfolders/Jonty/Rawdata_files/Client_ID_12_months_bill.txt';
input      client_ID $ January Dollar10.2 Febuary Dollar10.2 March Dollar10.2 April Dollar10.2 May Dollar10.2 June Dollar10.2 July                      Dollar10.2 August Dollar10.2 September Dollar10.2 October Dollar10.2 November Dollar10.2 December Dollar10.2;
run;


Accepted Solutions
Solution
‎07-19-2017 01:46 PM
PROC Star
Posts: 7,363

Re: raw data fetching

Answer depends upon whether you want to output records for all months or only those with non-missing balances. The following is for the latter:

data Bill_Summary (keep=client_ID balance month_num month_name);
  infile  '/folders/myfolders/Jonty/Rawdata_files/Client_ID_12_months_bill.txt' truncover;
  informat month1-month12 Dollar10.2;
  input      client_ID $ month1-month12;
  array months(*) month1-month12;
  do i=1 to dim(months);
    if not missing(months(i)) then do;
      balance=month(i);
      month_num=i;
      month_name=put(mdy(i,1,2017),monname.);
      output;
    end;
  end;
run;

Art, CEO, AnalystFinder.com

 

View solution in original post


All Replies
Solution
‎07-19-2017 01:46 PM
PROC Star
Posts: 7,363

Re: raw data fetching

Answer depends upon whether you want to output records for all months or only those with non-missing balances. The following is for the latter:

data Bill_Summary (keep=client_ID balance month_num month_name);
  infile  '/folders/myfolders/Jonty/Rawdata_files/Client_ID_12_months_bill.txt' truncover;
  informat month1-month12 Dollar10.2;
  input      client_ID $ month1-month12;
  array months(*) month1-month12;
  do i=1 to dim(months);
    if not missing(months(i)) then do;
      balance=month(i);
      month_num=i;
      month_name=put(mdy(i,1,2017),monname.);
      output;
    end;
  end;
run;

Art, CEO, AnalystFinder.com

 

Super User
Posts: 17,868

Re: raw data fetching

It's often a good idea to separate your formats from your INPUT statement. You can do it, but it's easier, IMO, to separate them out and then it tends to work as expected.  

 

If you run a PROC IMPORT first, set GUESSINGROWS to a high number and then use/modify the code in the log as needed.

 


jonty wrote:
  1. “Client_ID_12_months_bill.txt” contains the 12 months credit card bill against each client_id in single Import the data into SAS such that bill for each month is recorded as a separate observation and month number is also specific (Bonus question – Month name instead of month number)
  2. Import “Client_ID_12_months_bill(missing).txt” into SAS considering that there are churners in the data who left the company at different points of time during the year.

 

Data :-  

102563           $167.00  $125.00  $976.00  $483.00  $517.00  $797.00  $879.00  $988.00  $910.00  $451.00  $468.00  $236.00

 

Kindly help :-

my code :- 

 

data      Bill_Summary;
infile      '/folders/myfolders/Jonty/Rawdata_files/Client_ID_12_months_bill.txt';
input      client_ID $ January Dollar10.2 Febuary Dollar10.2 March Dollar10.2 April Dollar10.2 May Dollar10.2 June Dollar10.2 July                      Dollar10.2 August Dollar10.2 September Dollar10.2 October Dollar10.2 November Dollar10.2 December Dollar10.2;
run;


 

Contributor
Posts: 25

Re: raw data fetching

thanxx Reeza i did that with informat and formats it worked thanxx BTW
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 146 views
  • 1 like
  • 3 in conversation