BookmarkSubscribeRSS Feed
karen_e_wallace
Obsidian | Level 7

y sub
Hello,

My task is taking DNA sequences that are 60 characters long and creating 60 different variables (e.g. d1 - d60).

Variable D1 holds the DNA at the first position, D2 at the 2nd position...all the way to D60 at the 60th position.

I'm attaching the code below I have so far with some a data sample - I'm able to create the 60 variables but cannot get them populated correctly.

Any advice is much appreciated.

Regards,

Karen

data dna;

length dna $ 60;

input dna $;

datalines;

TGGAAGGGCTAATTTGGTCCCAAAAAAGACAAGAGATCCTTGATCTGTGGATCTACCACA


TGATTGGCAGAACTACACACCAGGGCCAGGGATCAGATATCCACTGACCTTTGGATGGTG

;

data dna2 (drop=i);

set dna;

counter=0;

array d(*) d1-d60;

do i=1 to dim(d);

if d(i) in ('C','A','T','G') then counter + 1;

substr(dna, I, 1)=d(i);

end;

run;

















4 REPLIES 4
Reeza
Super User

data dna2 (drop=i);

set dna;


array d(*) $ d1-d60;

do i=1 to dim(d);


d(i)=substr(dna, i,1);

end;

run;

Astounding
PROC Star

An easy variation to define each of the new variables as being 1 character long:

array d (*) $ 1 d1-d60;

Tom
Super User Tom
Super User

If you are reading from a raw file then read it directly into the array.

data want ;

   input (d1-d60) ($1.) ;

   count=lengthn(_infile_);

cards;

TGGAAGGGCTAATTTGGTCCCAAAAAAGACAAGAGATCCTTGATCTGTGGATCTACCACA

TGATTGGCAGAACTACACACCAGGGCCAGGGATCAGATATCCACTGACCTTTGGATGGTG

;;;;

If you already have a variable you can use a dummy input record to trick SAS into letting you use an INPUT statement.

data want ;

   set have ;

   input @@ ;

   _infile_ = dna ;

   input @1 (d1-d60) ($1.) @@ ;

   count=lengthn(dna);

cards;

DUMMY RECORD

;;;;

karen_e_wallace
Obsidian | Level 7

Thanks everyone for your help!

I finally tweaked it:

data dna2;

set dna;

array d{60} $1 D1-D60;

do i= 1 to 60;

d{i}=substr(dna,i,1);

end;

drop dna i;

run;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1255 views
  • 7 likes
  • 4 in conversation