Help using Base SAS procedures

Scan

Reply
N/A
Posts: 0

Scan

Hi,

I'm am reletively new to SAS and i am trying to write some code to split up a character string and import it into a table. Most of what i have done works ok but i am having problems with the following:

Username = scan(_blob_,1,",")
Balance = scan(_blob_,2,",");
Pending_bonus_balance = scan(_blob_,3,",");
Bonus_balance = scan(_blob_,4,",");
Total_bonus = scan(_blob_,5,",");
Poker_nickname = scan(_blob_,6,",");
Has_played_poker_download = scan(_blob_,7,",");
Last_bonus = scan(_blob_,8,",");
Last_bonus_date = scan(_blob_,9,",");
Poker_rakes = scan(_blob_,10,",");

The file that i am reading from contains a few thousend rows like this:
NUMERATOR,0,0,0,849.4,Numerator,1,0,,4040.364404
HIPPO,91.94,0,0,,FantasticHippo,1,0,,133.1472401
TECHALL,0,0,0,,Techall,1,0,,3.13005324
QUILLIUS,0,0,0,,quillius,1,0,,118.7320193

The problem comes when its gets to the ,, fields. It ignores the fact that it is empty and just pushes everything along one column. I have tried writing IF statements to fill the empty cells but that did not help.

Help anyone?

Thanks
N/A
Posts: 0

Re: Scan

instead of SCAN() it sounds like you want to look at how the INFILE and INPUT statements can help you. A very significant feature is the DSD option of the INFILE statement

good luck

PeterC
N/A
Posts: 0

Re: Scan

Welcome to the wonderful (full of wonder) rich world of SAS and SAS programming.
SAS was originally written for non-programmers, so there is generally an easy or easier way of doing things.

You are doing this the hard way.

The easy way is
[pre]
DATA captured;
INFILE indata delimiter=',' dsd;

INPUT Username balance pending_bonus_balance total_bonus poker_nickname has_played_poker_download last_bonus last_bonus_date poker_rates;
RUN;
QUIT;
[/pre]
This code example is not perfect, I haven't tested it.
Find the Web online documentation for BaseSAS for 9.1.x or your version of SAS and begin reading.

SAS is not your normal programming language. It is data centric and meant to simplify the programming process of reading data in, processing the data, and reporting on the results of the processing. It is very rich in features, it is so extensive, I expect no one knows all of it in complete detail.
Ask a Question
Discussion stats
  • 2 replies
  • 142 views
  • 0 likes
  • 1 in conversation