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

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!

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.

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
  • 740 views
  • 0 likes
  • 3 in conversation