BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
deleted_user
Not applicable
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
deleted_user
Not applicable
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.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 713 views
  • 0 likes
  • 1 in conversation