超经典的SAS BASE的笔记4.docx

上传人:b****5 文档编号:2858793 上传时间:2022-11-16 格式:DOCX 页数:17 大小:20.53KB
下载 相关 举报
超经典的SAS BASE的笔记4.docx_第1页
第1页 / 共17页
超经典的SAS BASE的笔记4.docx_第2页
第2页 / 共17页
超经典的SAS BASE的笔记4.docx_第3页
第3页 / 共17页
超经典的SAS BASE的笔记4.docx_第4页
第4页 / 共17页
超经典的SAS BASE的笔记4.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

超经典的SAS BASE的笔记4.docx

《超经典的SAS BASE的笔记4.docx》由会员分享,可在线阅读,更多相关《超经典的SAS BASE的笔记4.docx(17页珍藏版)》请在冰豆网上搜索。

超经典的SAS BASE的笔记4.docx

超经典的SASBASE的笔记4

Topic:

OverviewofMultipleDataSets

1.ConcatenatingdatasetusingSetstatement

2.Interleavingseveraldatasets

3.Modifying(creating)dataset

4.ConcatenatingdatasetusingPROCAPPEND

5.Mergingdatasets

6.Updatingdataset

7.PROCEXPORT/IMPORT

8.PROCCONTENTS

 

Overview

OneofSAS’sgreateststrengthsisitsabilitytocombineandprocessmorethanonedatasetatatime.ThemaintoolsusedtodothisaretheSET,MERGEandUPDATEstatements.

1.ConcatenatingdatasetusingSetstatement

ItreadsanobservationfromoneormoreSASdatasets.TheSETstatementisflexibleandhasavarietyofusesinSASprogramming.TheseusesaredeterminedbytheoptionsandstatementsthatyouusewiththeSETstatement:

dataone;

inputyearpop$@@;

datalines;

1991500K1992501K1993502K

;

datatwo;

inputyearpop$@@;

datalines;

1991400K1992401K1993402K

;

datathree;

inputyearpop$@@;

datalines;

1991300K1992301K1993302K1994303K

;

datacombine_1;

setonetwothree;

run;

datacon1;

inputcustom_id$product$12.;

cards;

28901pentiumIV

36815pentiumIII

21224pentiumIV

;

datacon2;

inputcustom_id$product$12.;

cards;

18601pentiumIV

24683pentiumIII

851921pentiumIV

61831pentiumIV

;

datacon3;

setcon1;

setcon2;

run;

2.Interleavingseveraldatasets

Ifyouwanttocombineseveraldatasetssothatobservationssharingacommonvaluearealladjacenttoeachother,youcanlistthedatasetsonSETstatement,andspecifythevariabletobeusedonaBYstatement.Note:

Thedatasetstobeinterleavedmustalreadybesortedbythevariable(s)listedintheBYstatement.

/*Creatinganewdatasetfrommultipledatasetsbaseduponsortedorder*/;

dataanimal;

inputcommon$animal$;

datalines;

aAnt

aApe

bBird

cCat

dDog

;

dataplant;

inputcommon$plant$;

datalines;

aApple

bBanana

cCoconut

dDewberry

eEggplant

fFig

;

datainterleaving;

setanimalplant;

bycommon;

run;

procprintdata=interleaving;

run;

3.TheSETstatementisusedtomodifyanexistingSASdataset

andReadingObservationsUsingDirectAccess

dataold;

inputx1-x3;

datalines;

123

345

;

datanew;

setold;

xtot=sum(ofx1-x3);

run;

dataa;

inputxy@@;

cards;

90119022903390449055

;

datab;

x=2;/*selectagivenobs*/

setapoint=x;

output;

stop;

run;

Tocreateatemporarynumericvariablewhosevalueisusedtodetectthelastobservation,youcanusetheEND=optionintheSETstatement.

dataen;

inputaccntbalanceday@@;

cards;

9014861901985490349829034982

;

dataen2;

setenend=last;

iflast;

run;

4.ConcatenatingdatasetusingPROCAPPEND

ConcatenatingSASdatasetsistheprocessofstoringobservationsoneafteranotheruntilallthedatasetsandtheirobservationshavebeencombinedintoonedataset.

ManyusersperformtheconcatenationprocessusingaDATAstep(asshowninthepreviousexamples),buttherearegoodreasonsforusingtheAPPENDprocedure.IfyouusetheSETstatementinaDATAsteptoconcatenatetwodatasets,theSASSystemmustprocessalltheobservationsinbothdatasetstocreateanewone.TheAPPENDprocedurebypassestheprocessingofdataintheoriginaldatasetandaddsnewobservationsdirectlytotheendoftheoriginaldataset.Itdoesthisbypositioningtherecordpointerattheendoftheoriginaldataset,andstartingtheprocessingdirectlywiththenewobservations.

PROCAPPEND

Syntax:

BASE=SAS-data-set

SincePROCAPPENDreadsonlytheseconddataset,setBASE=tothelargerdataset.However,theorderofthedatasetsdoesnotmatter.

datamaster;

inputcity$1-11month$10.temp;

cards;

HonoluluAugust80.7

HonoluluJanuary72.3

BostonJuly73.3

BostonJanuary29.2

DuluthJuly65.6

DuluthJanuary8.5

NewYorkAugust82.7

NewYorkJanuary22.3

;

dataadd;

inputcity$1-11month$10.temp;

cards;

RaleighJuly77.5

RaleighJanuary40.5

MiamiAugust82.9

MiamiJanuary67.2

LosAngelesAugust69.5

LosAngelesJanuary54.5

;

run;

procappendbase=masterdata=add;

run;

dataweather;

inputdatemmddyy8.tempsunhrs;

cards;

01-01-90359.3

01-02-90349.33

01-03-90379.35

01-04-90389.39

;

datadaily;

inputdatemmddyy8.tempsunhrsprecip;

cards;

01-05-90359.401.1

;

run;

procappendbase=weatherdata=dailyforce;

run;

Whataretheadvantagesor/anddisadvantagesofSETstatementandPROCAPPEND?

1.PROCAPPENDismoreefficientforappendingtwodatasets.BecausePROCAPPENDperformsanupdateinplaceontheBASE=dataset;therefore,itjustaddstheobservationsfromtheDATA=datasettotheendoftheBASE=dataset.TheobservationsintheBASE=datasetarenotreadorprocessed.

2.TheDATAwithSETdoesnotperformanupdateinplace

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 互联网

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1