LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 20 Feb 2006 15:53:46 -0600
Reply-To:     Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Subject:      Re: Creating SAS Dataset
Comments: To: mehedisas@YAHOO.COM
Content-Type: text/plain; charset=US-ASCII

Try the following code and see the output follows the code. In the code below there are two datasets: Temp and name. Temp is the same as what you have as the first dataset. Dataset Name has four names in it, two in Temp and the others not in Temp. Write back if you have questions implementing it.

options mlogic mprint symbolgen; data Temp; input @1 A percent2. @4 B percent4. C $ D; datalines; 2% 4% Jeb 2 4% 1% Hilary 2 5% 1.6% Josh 2.8 9% 3.1% Rock 3.8 ; run;

data name; input E $; datalines; Bush Jeb Clinton Hilary ; run;

%macro AddObs(One=,Two=); data _null_; if 0 then set &Two nobs=NameCount; call symput('NameCount',compress(put(NameCount,4.))); run; %do i=1 %to &NameCount; data _null_; obsnum=&i; set &Two point=obsnum; call symput('E',compress(E)); stop; run; %put &E; proc sql noprint; select count(*) into :NameCount from &One where compress(C) eq %unquote(%str(%'&E%')); %if &NameCount eq 0 %then %do; insert into temp (A, B, C, D) values%unquote(%str(%(0, 0, %'&E%', 0%))); select * from &One; %end; quit; %end; %mend AddObs;

%AddObs(One=Temp,Two=Name) proc print data=Temp; run;

***** Output ***** The SAS System 15:12 Monday, February 20, 2006 71

Obs A B C D

1 0.02 0.040 Jeb 2.0 2 0.04 0.010 Hilary 2.0 3 0.05 0.016 Josh 2.8 4 0.09 0.031 Rock 3.8 5 0.00 0.000 Bush 0.0 6 0.00 0.000 Clinton 0.0

J S Huang 1-515-557-3987 fax 1-515-557-2422

>>> Rathindronath <mehedisas@YAHOO.COM> 2/20/2006 1:41:53 PM >>> I am trying to check if some observations are in a dataset, if they are not then I want to add them in that given dataset.. such as in my given dataset there is 4 variables as below ( A, B, C, and D):

A B C D 2% 4% Jeb 2 4% 1% Hilary 2 5% 1.6% Josh 2.8 9% 3.1% Rock 3.8

Now I have to check if all the values for the variable C is available. For the variable C the values are be Jeb, Hilary, Bush, Clinton, Josh, and Rock. But Bush and Clinton is not the given dataset. So I have to check first and then determine which values of the variable C are not in the given dataset and then I have to add the missing vales with complete observations to that given dataset. I have here the name for bush and clinton that are missing. I have to assign value Zero for the variables of the missing value for C.

A B C D 0.0% 0.0% Bush 0.0 0.0% 0.0% Clinton 0.0

Note: Any variable that was not included in the given dataset should have a O.0 % for the variable A, B and D. And finally I need a dataset as follows:

A B C D 2% 4% Jeb 2 0.0% 0.0% Bush 0.0 4% 1% Hilary 2 5% 1.6% Josh 2.8 0.0% 0.0% Clinton 0.0 9% 3.1% Rock 3.8

Note: the sequence of these observations in this prospective dataset are given. Like First value is Jeb, second Bush, Third Hilary ....Can Anyone please help me with this?


Back to: Top of message | Previous page | Main SAS-L page