楼主: ertyuj
1889 6

[问答] 要崩溃了-帮忙看行code吧 [推广有奖]

  • 0关注
  • 1粉丝

已卖:7份资源

硕士生

40%

还不是VIP/贵宾

-

威望
0
论坛币
254 个
通用积分
0.7615
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
-351 点
帖子
136
精华
0
在线时间
164 小时
注册时间
2007-2-7
最后登录
2022-3-17

楼主
ertyuj 发表于 2017-9-2 12:36:51 |AI写论文
25论坛币
我有三个变量,x,y,z。我要做的事情是,生成x_new=x*2,y_new=y*2,z_new=z*2.我使用使用如下SAS发布的macro,未作任何改动,仅仅加了一行。然后在下面的data step调试,死活报错(ERROR 180-322: Statement is not valid or it is used out of proper order.)急急急!求帮忙!在线等。

***************
这是SAS发布的MACRO: Sample 26155: Loop through a nonsequential list of values with a macro DO loop

%macro loop(values);   
                                                                                                               
     /* Count the number of values in the string */                                                                                                                                   
     %let count=%sysfunc(countw(&values));

     /* Loop through the total number of values */                                                                                         
     %do i = 1 %to &count;                                                                                                              
      %let value=%qscan(&values,&i,%str(,));                                                                                            
      %put &value;   


&value._new=&value*2;

     %end;                                                                                                                              
                                                                                                                                       
%mend;                                                                                                                                 
                                                                                                                                       
这是我的调试代码,会报错:(ERROR 180-322: Statement is not valid or it is used out of proper order.)
data t;
x=1;
y=2;
z=3;
%loop(%str(x,y,z)) ;
run;

关键词:code COD ODE Sequential statement
数据科学和机器学习博客:https://shorturl.at/jtHTW

沙发
ertyuj 发表于 2017-9-2 12:42:37
这是我加的那行:&value._new=&value*2;
去掉这行,没有任何问题。帮忙看看这行到底是啥毛病啊!!!

藤椅
67890 发表于 2017-9-2 19:17:13
&value._new=&value*2;
设&value=2,新变量是“2_new”,变量名不合法。

板凳
lyfyb99 在职认证  发表于 2017-9-3 21:43:28
我试了一下,把%qscan 换成 %scan 就好了:

%macro loop(values);   
                                                                                                               
     /* Count the number of values in the string */                                                                                                                                   
     %let count=%sysfunc(countw(&values));

     /* Loop through the total number of values */                                                                                         
     %do i = 1 %to &count;                                                                                                              
      %let value=%scan(&values,&i,%str(,));                                                                                            
      %put &value;   


&value._new= &value.*2;

     %end;                                                                                                                              
                                                                                                                                       
%mend;      

data t;
x=1;
y=2;
z=3;
%loop(%str(x,y,z)) ;
run;

报纸
jjjch 发表于 2017-9-4 23:20:42
你为什么要自动生成 x_new=x*2,y_new=y*2,z_new=z*2 这3条语句?

如果你准备用(x,y,z)去调用一个宏%loop(%str(x,y,z))来生成那3条语句,还不如就自己手写那3条语句。

我想你并没有把你的真实的最终的目的写出来。


地板
sonypam 在职认证  发表于 2017-9-8 04:32:38
lyfyb99 is correct. My understanding is qscan masks the comma(,) in the string.

7
sas9.4 发表于 2017-9-22 22:19:13
why not use ? array ?

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

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