Help using Base SAS procedures

how to delete variables

Reply
N/A
Posts: 0

how to delete variables

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
Frequent Contributor
Posts: 97

Re: how to delete variables

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
N/A
Posts: 0

Re: how to delete variables

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
Super Contributor
Posts: 474

Re: how to delete variables

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
Frequent Contributor
Posts: 97

Re: how to delete variables

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
Ask a Question
Discussion stats
  • 4 replies
  • 131 views
  • 0 likes
  • 3 in conversation