DATA Step, Macro, Functions and more

Skip over a variable and continue

Reply
Contributor
Posts: 59

Skip over a variable and continue

I wrote the following code to extract a flat file into sas
data lib.test2;
length Rank 3 Code1 $3 Drug $25 Manufacturer $25 Sales 8 PerChg 8;
infile 'c:\Test2.txt' DLM=' ()';
input Rank Code1 Drug Manufacturer Sales PerChg ;
run;

Here is a sample of what the data looks like in the flat file

3 Plavix Bristol-Myers Squibb Company 4,223,124 11.2%
4 Advair Diskus GlaxoSmithKline 3,653,410 2.3%
5 (1) Seroquel AstraZeneca Pharmaceuticals 3,117,591 7.2%
6 (6) Abilify Bristol-Myers Squibb Company 3,083,351 30.0%
7 Singulair Merck & Co., Inc. 3,027,378 4.5%
The reason I have a variable called Code1 is because some of the entries have a number with parenthesis. Two of the entries have such a sequence. Is there a way to skip the numbers with a parenthesis. All I really want is
Rank
Drug
Manufacturer
Sales
Percentage
Respected Advisor
Posts: 3,799

Re: Skip over a variable and continue

Posted in reply to omega1983
This works but I also added spaces following the drug name and company. These fields have more than one blank delimited word and with LIST input you need two spaces to delimit those fields. I don't know if this is an issue in your actual data or not.

[pre]
data test;
length Rank 3 Drug $25 Manufacturer $25 Sales 8 PerChg 8;
infile cards;
input rank @;
if index(_infile_,')') then input @(')') @;
input (Drug Manufacturer)(&) (Sales PerChg) (:comma.);
cards;
3 Plavix Bristol-Myers Squibb Company 4,223,124 11.2%
4 Advair Diskus GlaxoSmithKline 3,653,410 2.3%
5 (1) Seroquel AstraZeneca Pharmaceuticals 3,117,591 7.2%
6 (6) Abilify Bristol-Myers Squibb Company 3,083,351 30.0%
7 Singulair Merck & Co., Inc. 3,027,378 4.5%
;;;;
run;
proc print;
run;
[/pre] Message was edited by: data _null_;
Super Contributor
Super Contributor
Posts: 365

Re: Skip over a variable and continue

Posted in reply to omega1983
Hello Omega1983,

A solution could be to exclude the Code1 variable including (1) and (6) into the Drug variable and then use the following code:

Drug=SUBSTR(Drug,ANYALPHA(Drug));

that excludes (1) and (6) or anything else up to the first letter in the Drug variable.

Sincerely,
SPR
Ask a Question
Discussion stats
  • 2 replies
  • 128 views
  • 0 likes
  • 3 in conversation