BookmarkSubscribeRSS Feed
omega1983
Calcite | Level 5
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
2 REPLIES 2
data_null__
Jade | Level 19
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_;
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1233 views
  • 0 likes
  • 3 in conversation