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;
