BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello all
Here is my raw data:

Mike 35 male tall smoker
12312354152612
1231243612436152436
12123451432451
1234512315423
142351323123
Sara 26 female short smoker
12222221423541
14253513254
1231243142
12434541235142543
Monica 24 female short nonsmoker
124152345142
1423451324
1243541325
124354132
1
12134124124351
123451324312541323
13245312435412

The first line has basic information about the observation, then there are numerous variables( they are test scores values from 1-6 )
I found out that only the first five scores are needed and to delete everything else
How do I just retain the first line and only the first 5 scores and then move to the second observation (Sara)

this is how I want my output:
Mike 35 male tall smoker 12312
Sara 26 female short smoker 12222
Monica 24 female short nonsmoker 12415


Any help would be greatly appreciated.
SAS newbie
4 REPLIES 4
cjohnson
Obsidian | Level 7
Try this:

data test;
infile "data.txt" dlm=" ";
input name $ @@;
if compress(name,"0123456789") = name;
input age gender $ height $ smoker $ / score1 1 score2 2 score3 3 score4 4 score5 5;
run;
Christopher Johnson
www.codeitmagazine.com
deleted_user
Not applicable
Wow, thanks so much!
How does it work?
I am looking into compress function but still dont know how does it work?
also
lets say I want to read the first 5 observation of each line, do i just create a do loop?
thanks again Message was edited by: bluelion
DanielSantos
Barite | Level 11
Hi.

Check the online doc for the COMPRESS function:
http://support.sas.com/documentation/cdl/en/tsref/59770/HTML/default/a003081143.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
cjohnson
Obsidian | Level 7
Here is how it works. The datastep reads in the file data.txt, which we are saying is space delimited. It then reads the first variable into name. The @@ says don't go to the next line yet. SAS doesn't have an isnumeric function, so we test it by removing the numbers with compress and seeing if we changed it. If not, then we read in the rest of the variables (the / says go to the next line for the rest of the variables).

Not sure what you mean by the first 5 observations of each line. The data step has a built in loop, so you won't need a do loop. Do you mean you want to read in only 5 records total?
Christopher Johnson
www.codeitmagazine.com

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
  • 4 replies
  • 684 views
  • 0 likes
  • 3 in conversation