BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonty
Fluorite | Level 6
  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;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

3 REPLIES 3
art297
Opal | Level 21

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

 

Reeza
Super User

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;


 

jonty
Fluorite | Level 6
thanxx Reeza i did that with informat and formats it worked thanxx BTW

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 873 views
  • 1 like
  • 3 in conversation