Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to merge the data using merge statement and proc format?
Is the result is same ?

Answers were Sorted based on User's Feedback



How to merge the data using merge statement and proc format? Is the result is same ?..

Answer / lekha

I guess merge statement is different from Proc format. Merge Joins the observations from two or more SAS data sets into a single observation. Whereas proc format enables you to define your own informats and formats for variables.

Is This Answer Correct ?    11 Yes 2 No

How to merge the data using merge statement and proc format? Is the result is same ?..

Answer / ravi

/*********************/
/* Datasets creation */
/*********************/
data city_table1;
length city $12. state $4.;
input city $ state $;
datalines;
fresno ca
stockton ca
oakland ca
fremont ca
sacramento ca
irvine ca
Jacksonville fl
miami fl
tampa fl
orlando fl
hialeah fl
atlanta ga
augusta ga
columbus ga
savannah ga
macon ga
dallas tx
houston tx
austin tx
franklin tx
chicago il
;
run;


data city_table;
set city_table1;
sales = int(ranuni(3)*1000000);
format sales dollar10.;
run;


data state_table;
length state $4. full_state $10.;
input state $ full_state $;
datalines;
ca california
fl florida
ga georgia
tx texas
co colorado
;
run;


/***************************/
/* General merge statement */
/***************************/

proc sort data = city_table;
by state;
run;

proc sort data = state_table;
by state;
run;


data general_merge1;
merge city_table(in=a) state_table(in=b);
by state;
if a;
run;

data general_merge;
set general_merge1;
if full_state = '' then full_state = 'unknown';
run;


/************/
/* Sql Join */
/************/

proc sql;
create table sql_join1 as
select city_table.city, city_table.state, state_table.full_state, city_table.sales
from city_table left join state_table
on city_table.state = state_table.state
order by city_table.state;
quit;

data sql_join;
set sql_join1;
if full_state = '' then full_state = 'unknown';
run;


/**************/
/* Hash merge */
/**************/

data hash_merge(drop = rc);
length full_state $10;
if _N_ = 1 then do;
declare hash h_state(dataset:'state_table');
h_state.definekey('state');
h_state.DefineData ('full_state');
h_state.definedone();
end;
set city_table;

rc = h_state.find();

if rc ne 0 then full_state = 'unknown';

run;


/*********************/
/* proc format merge */
/*********************/

data key; set state_table (keep = state full_state);
/* These variables translate to the FORMAT values in the metadata */
fmtname = '$key';
label = full_state;
rename state = start;
run;

proc sort data=key;
by start;
run;

proc format cntlin=key;
run;

data format_merge;
set city_table;
length full_state $15.;
full_state=put(state,$key.);
if put(state,$key.) = state then full_state = 'unknown';
run;

Is This Answer Correct ?    6 Yes 1 No

Post New Answer

More SAS Interview Questions

if you have 365 no of data set and each one having different variable from each other. how will you read by creating macros and create a single data set.

2 Answers  


Why and when do you use proc sql?

0 Answers  


which date function advances a date, time or datetime value by a given interval? : Sas programming

0 Answers  


What are all the problems you faced while validating tables and reports?

0 Answers   Accenture, Quintiles,


What is the purpose of the trailing and How would you use them?

8 Answers  


What is SAS? is it a software just for use or we can creat something over there?

5 Answers   Cognizant,


How to select the observations randomly from a SAS dataset

7 Answers   NTT Data,


how can u convert this 25-jul-2010 from numeric to charcter?

3 Answers  


how can you get the single data set from the library(which has the number of data sets)?

3 Answers   Accenture, Deloitte,


How do i read multiple spaces in datasets?

4 Answers   Quintiles,


Mention common programming errors committed in sas ?

0 Answers  


How many ways to overcome a missing values???

0 Answers   HSBC,


Categories