Copying observations

  • Follow


Hi! This is my first time posting here and I need help. :)

Suppose you have a raw data that look like this:
12345 yes
	  no
	  yes
67890 no
	  yes
	  yes
4321	  no
9876	  yes

Those with blanks must be filled with numbers that precede them (i.e.
12345 must be followed also by 12345 and 12345 depending on how many
blanks are there). Same goes with 67890.

Many thanks for those who will respond! :)
0
Reply menniesa.medina (2) 5/2/2012 1:50:28 PM

On May 2, 9:50=A0pm, neng medina <menniesa.med...@gmail.com> wrote:
> Hi! This is my first time posting here and I need help. :)
>
> Suppose you have a raw data that look like this:
> 12345 yes
> =A0 =A0 =A0 =A0 =A0 no
> =A0 =A0 =A0 =A0 =A0 yes
> 67890 no
> =A0 =A0 =A0 =A0 =A0 yes
> =A0 =A0 =A0 =A0 =A0 yes
> 4321 =A0 =A0 =A0no
> 9876 =A0 =A0 =A0yes
>
> Those with blanks must be filled with numbers that precede them (i.e.
> 12345 must be followed also by 12345 and 12345 depending on how many
> blanks are there). Same goes with 67890.
> What SAS code will I use for this?
>
> Many thanks for those who will respond! :)

0
Reply menniesa.medina (2) 5/2/2012 2:03:47 PM


On Wednesday, May 2, 2012 6:50:28 AM UTC-7, neng medina wrote:
> Hi! This is my first time posting here and I need help. :)
> 
> Suppose you have a raw data that look like this:
> 12345 yes
> 	  no
> 	  yes
> 67890 no
> 	  yes
> 	  yes
> 4321	  no
> 9876	  yes
> 
> Those with blanks must be filled with numbers that precede them (i.e.
> 12345 must be followed also by 12345 and 12345 depending on how many
> blanks are there). Same goes with 67890.
> 
> Many thanks for those who will respond! :)

Look at the retain statement. 

data want;
set have;
retain id_filled;
if id ne . then id_filled=id;
run;

www.ats.ucla.edu/stat/sas/library/nesug99/bt064.pdf
0
Reply fkhurshed1 (354) 5/2/2012 3:58:55 PM

On Wed, 2 May 2012 06:50:28 -0700 (PDT), neng medina
<menniesa.medina@gmail.com> wrote:

>Hi! This is my first time posting here and I need help. :)
>
>Suppose you have a raw data that look like this:
>12345 yes
>	  no
>	  yes
>67890 no
>	  yes
>	  yes
>4321	  no
>9876	  yes
>
>Those with blanks must be filled with numbers that precede them (i.e.
>12345 must be followed also by 12345 and 12345 depending on how many
>blanks are there). Same goes with 67890.
>
>Many thanks for those who will respond! :)

Look at the RETAIN statement and the MISSING function.

-- 
Remove del for email
0
Reply schwarzb3978 (1358) 5/2/2012 7:35:40 PM

On Wed, 2 May 2012 08:58:55 -0700 (PDT), Reeza <fkhurshed@gmail.com>
wrote:

>On Wednesday, May 2, 2012 6:50:28 AM UTC-7, neng medina wrote:
>> Hi! This is my first time posting here and I need help. :)
>> 
>> Suppose you have a raw data that look like this:
>> 12345 yes
>> 	  no
>> 	  yes
>> 67890 no
>> 	  yes
>> 	  yes
>> 4321	  no
>> 9876	  yes
>> 
>> Those with blanks must be filled with numbers that precede them (i.e.
>> 12345 must be followed also by 12345 and 12345 depending on how many
>> blanks are there). Same goes with 67890.
>> 
>> Many thanks for those who will respond! :)
>
>Look at the retain statement. 
>
>data want;
>set have;
>retain id_filled;
>if id ne . then id_filled=id;
>run;

There appears to be a KEEP and an ELSE missing.

-- 
Remove del for email
0
Reply schwarzb3978 (1358) 5/3/2012 5:35:27 PM

What do you mean? What do you need a KEEP and ELSE for? 
0
Reply fkhurshed1 (354) 5/3/2012 8:38:50 PM

On Thu, 3 May 2012 13:38:50 -0700 (PDT), Reeza <fkhurshed@gmail.com>
wrote:

>
>What do you mean? What do you need a KEEP and ELSE for? 

The KEEP (or DROP) is needed to eliminate id_filled from the output.

The ELSE is needed because if id is missing it needs to be updated
with saved value in id_filled.

-- 
Remove del for email
0
Reply schwarzb3978 (1358) 5/4/2012 5:47:15 PM

6 Replies
19 Views

(page loaded in 0.075 seconds)


Reply: