sasprocsqlinto
Ⅰ sas 中有什麼函數可以檢查我需要的欄位是不是包含在指定變數中
可以用index();來確定需要的欄位在指定變數中位置,如果沒有結果是「0」;
例如:
data a;
input group $1 x1 x2;
cards;
A 5 6
B 4 3
C 6 8
;
run;
proc print data=a noobs;
where index(group,'C')>0;
run;
就成了!
Ⅱ 請教SAS如何提取觀測的個數
data _null_;
If 0 then set aa nobs=n;
Call symput('N',n);
Run;
%put &n.;
Ⅲ sas裡面,怎麼把數據平均分三組,每組按照大小順序分
一個簡單的演算法,若有30個數據,分三組,一組10個,按從小到大排序,用_n_/10取整就好了嘛,第一組為0,第二組1,第三組2
Ⅳ SAS宏技術中,%let和call symput有什麼區別
平時經常使用的宏變數定義方法有三種:
1. %let xxx=yyy;
2. Call Symput('xxx','yyy');
3. select xxx into: yyy.
三種定義方式最大的區別是在MACRO函數內定義所生成的宏變數的類型不同:
Call Symput在宏函數中定義的宏變數可以在函數外調用;而%let和 Select into則不能,因為這2種方法在MACRO函數內生成的是局部宏變數,若要想在MACRO函數外調用,需事先用%global申明變數類型。
%macro test();
data _NULL_;
call symput('Today',put(today(),date9.));
run;
Method 2
%let today=%sysfunc(today(),date9.);
Method 3
data todaydate;
date=today();
Proc sql noprint;
select put(date,date9.) INTO: today
from todaydate
;
quit;
%put &today;
%mend;
%test;
%put &today;
Ⅳ SAS庫欄位更新問題 如何使用SQL的replace函數更新SAS資料庫中的欄位,具體如下
SAS沒有replace函數,有字元替換功能的倒是translate函數。試試下面的程序:
proc sql;
update t
set f=translate(f,'-','_');
quit;
Ⅵ 求助sas code:如何按年份看一個變數是否連續兩年以上(含)出現過。
您好,這樣:
proc sort data=special;
by special;
run;
proc sql noprint;
select special into :special_list SEPARATED BY " " from special;
select count(*) into: num from special;
quit;
%put &special_list #
data giveyou(drop=j special);
set base;
do j=1 to #
set special point=j;
array var_{&num} &special_list;
if index(var1,trim(special))>0 then var_(j)=1;
end;
output;
run;
Ⅶ 關於SQL語句。綜合分析題。急~
1.create database cpxs -----創建cpxs資料庫
go
2.create table 產品表 -----創建產品表
(產品編號 varchar(50),
產品名稱 varchar(100),
庫存量 int)
go
create table 銷售商表 -----創建銷售商表
(客戶編號 varchar(50),
客戶名稱 varchar(100),
地區 varchar(100),
負責人 varchar(50),
電話 varchar(20))
go
create table 產品銷售表 -----創建產品銷售表
(銷售日期 datetime,
產品編號 varchar(50),
數量 int,
價格 float)
go
----產品表中插入如下數據('0001','計算機',20)
insert into 產品表
values('0001','計算機',20)
go
----銷售商表中將負責人「劉濤」的電話號碼改為「1398888888」
update 銷售商表
set 電話='1398888888'
where 負責人='劉濤'
go
4.----定義一個函數,求三個數的最大值
create function MAXNUM(@num1 float,@num2 float,@num3 float)
returns float
begin
declare @max float
select @max=@num1
if @num2>=@max
select @max=@num2
if @num3>=@max
select @max=@num3
return @max
end
go
5.----創建一個存儲過程返回某種產品的產品名稱
create procere proct_information @proctnumber varchar(50)
as
select 產品名稱 from 產品表
where 產品編號=@proctnumber
go
Ⅷ 在SAS中怎麼批量地將數值型轉化為字元型
sas官網的例子:它是將數據中所有的字元型轉變為數值型,相應變化下就可以解決你的問題。
/*The sample data set TEST contains both character and numeric variables*/
data test;
input id $ b c $ d e $ f;
datalines;
AAA 50 11 1 222 22
BBB 35 12 2 250 25
CCC 75 13 3 990 99
;
/*PROC CONTENTS is used to create an output data set called VARS to list all */
/*variable names and their type from the TEST data set. */
proc contents data=test out=vars(keep=name type) noprint;
/*A DATA step is used to subset the VARS data set to keep only the character */
/*variables and exclude the one ID character variable. A new list of numeric*/
/*variable names is created from the character variable name with a "_n" */
/*appended to the end of each name. */
data vars;
set vars;
if type=2 and name ne 'id';
newname=trim(left(name))||"_n";
/*The macro system option SYMBOLGEN is set to be able to see what the macro*/
/*variables resolved to in the SAS log. */
options symbolgen;
/*PROC SQL is used to create three macro variables with the INTO clause. One */
/*macro variable named c_list will contain a list of each character variable */
/*separated by a blank space. The next macro variable named n_list will */
/*contain a list of each new numeric variable separated by a blank space. The */
/*last macro variable named renam_list will contain a list of each new numeric */
/*variable and each character variable separated by an equal sign to be used on*/
/*the RENAME statement. */
proc sql noprint;
select trim(left(name)), trim(left(newname)),
trim(left(newname))||'='||trim(left(name))
into :c_list separated by ' ', :n_list separated by ' ',
:renam_list separated by ' '
from vars;
quit;
/*The DATA step is used to convert the numeric values to character. An ARRAY */
/*statement is used for the list of character variables and another ARRAY for */
/*the list of numeric variables. A DO loop is used to process each variable */
/*to convert the value from character to numeric with the INPUT function. The */
/*DROP statement is used to prevent the character variables from being written */
/*to the output data set, and the RENAME statement is used to rename the new */
/*numeric variable names back to the original character variable names. */
data test2;
set test;
array ch(*) $ &c_list;
array nu(*) &n_list;
do i = 1 to dim(ch);
nu(i)=input(ch(i),8.);
end;
drop i &c_list;
rename &renam_list;
run;