楼主: 陶然
5648 11

请教:判断导入后的数据集为空集,然后跳出该步循环? [推广有奖]

  • 1关注
  • 3粉丝

已卖:6份资源

讲师

82%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
7.5000
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
3315 点
帖子
186
精华
0
在线时间
1002 小时
注册时间
2005-9-11
最后登录
2025-5-6

楼主
陶然 发表于 2013-8-20 12:05:42 |AI写论文
1论坛币
程序截部分如下:我尝试编了一段,大括号括起来了,不过不行,请高手指点
%macro excelexp(code);
data finacenew;
set finace;
if code NE "&code" then delete;
keep code month year transaction_yuan;
/*if missing(code)=1 then continue;!!!!!这里肿么编?*/
       {%if &obscount =0 %then %do;
          continue;
              %end;
        run;}
...*其他代码
%mend excelexp;

%macro exec(i);
%do j=1 %to &i;
%excelexp(code=&j);
%end;
%mend exec;

%exec(i=4);

易丹 2013-08-20


最佳答案

rickyking 查看完整内容

your question is still not that clear. however : you can use this code to create a macro variable that determines if the dataset is nil :once &obs_count is equal to 0, it is an empty data set. you can apply a macro if-then :
关键词:数据集 Transaction continue missing Finace 如何 continue 大括号 程序

沙发
rickyking 发表于 2013-8-20 12:05:43
陶然 发表于 2013-8-20 16:41
补充,循环应该这么写的:
%macro exec(i);
%do j=1 %to &i;
your question is still not that clear. however :

you can use this code to create a macro variable that determines if the dataset is nil :
  1. proc sql noprint;
  2.     select count(*) into :obs_count from dataset1;
  3. quit;
复制代码
once &obs_count is equal to 0, it is an empty data set. you can apply a macro if-then :
  1. %if (&obs_count ne 0) %then %do;
  2. ..........your code here
  3. %end;
复制代码

藤椅
陶然 发表于 2013-8-20 14:55:52
我面对的实际问题是:循环导入excel文件,但是有一些编号是缺失的,例如:000001.SZ, 000002.SZ, 000004.SZ, 000005.SZ, 000006.SZ...有没有办法不导入那些不存在的excel;我想的是判断导入后的集合为空集,然后跳出循环。

板凳
rickyking 发表于 2013-8-20 15:56:29
不懂你的问题
写详细一点

报纸
陶然 发表于 2013-8-20 16:11:51
rickyking 发表于 2013-8-20 15:56
不懂你的问题
写详细一点
让我组织一下语言

地板
陶然 发表于 2013-8-20 16:38:16
e.g.:
%macro a(i);
data finance01;
set finance; //这里finance是对绝大部分股票的信息概述的一个数据,股票编号用变量code表示,我这里简单
                       假设是从1,2,3...(字符型)编号,但是有一些号码缺失
if code NE "&i" then delete;  //只留含第“i”只股票的描述信息
PROC IMPORT OUT= WORK.FINANCE001 //这里文件夹里有2000个excel表格,表格名字为:1,2,3,4...但是
                                                           也有缺失(如没有名称为3的表格)
            DATAFILE= "D:\Eco\Finance\按月逐个A股成交量、金额等\&i.
.xls"
            DBMS=EXCEL REPLACE;
     RANGE="'&i$'";  //这一步引用了宏变量
     GETNAMES=YES;
     MIXED=NO;
     SCANTEXT=YES;
     USEDATE=YES;
     SCANTIME=YES;
RUN;
proc sort data=finance01;
by year month;
run;
proc sort data=finance001;
by year month;
run;
data f001Mf01;
merge finance001 finance01;
by year month;
run;
/*接下来是将f001Mf01 输出为excel表格以及其他运算*/
%mend a;
%a(2000)
问题是:我的总表中数值并不是连续的,以及文件夹中excel表格里文件名(数字)也不是连续的,我的构想是1或2成立时,跳出宏中的该步循环,其中1:if finance01 为空集;2:finance001为空集。
不知道是否清楚,求指点

7
陶然 发表于 2013-8-20 16:41:36
rickyking 发表于 2013-8-20 15:56
不懂你的问题
写详细一点
补充,循环应该这么写的:
%macro exec(i);
%do j=1 %to &i;
%a(i=&j);
%end;
%mend exec;

%exec(2000);

8
陶然 发表于 2013-8-20 17:46:16
rickyking 发表于 2013-8-20 16:54
your question is still not that clear. however :

you can use this code to create a macro variab ...
还想请教一下:如何在
proc sql noprint;
    select count(*) into :obs_count from dataset1;
quit;
quit后让它继续呢?

9
陶然 发表于 2013-8-20 17:48:45
rickyking 发表于 2013-8-20 16:54
your question is still not that clear. however :

you can use this code to create a macro variab ...
懂了!我在循环中删去了quit;quit是让我检验是否运行到这一步了,对吧

10
rickyking 发表于 2013-8-20 18:06:47
陶然 发表于 2013-8-20 17:48
懂了!我在循环中删去了quit;quit是让我检验是否运行到这一步了,对吧
quit is like run.
But it is a must to end the sql procedure if nothing after.Otherwise, when sas encounter a new proc, the sql statement will execute automatically.

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-2 08:19