我的数据集中有几个(确切的55个)变量是大块文本。这些变量包含某些医疗程序的结果。
我正在尝试将索引函数与SAS中的数组结合使用,以识别55个结果变量中的一个或多个中存在某些关键字的观察结果。例如,“REPAIR”一词出现。
data c1;
set c;
array res results1-results55;
array outres _numeric_;
do i= 1 to dim(outres);
outres(i) = index(res(i), "REPAIR");
end;
run;
当只有一个变量被索引时,我可以让我的代码工作;但是,当尝试使用数组查看“REPAIR”一词的所有55个结果变量时,它会中断。我收到以下错误:
ERROR: Array subscript out of range at line 1338 column 19.
有关如何调试此问题的想法吗?
谢谢!
答案 0 :(得分:1)
您要求SAS从所有现有数字变量中生成数组import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
import java.util.Arrays;
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.Point;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
class Planet {
public float x;
public float y;
public float w;
public float xv;
public float yv;
public Planet(float xn,float yn,float wn,float xvn,float yvn) {
x=xn;
y=yn;
w=wn;
yv=yvn;
xv=xvn;
}
public float distance(Planet planet) {
float xdis=x-planet.x;
float ydis=y-planet.y;
return (float)Math.sqrt((xdis*xdis)+(ydis*ydis));
}
public void move() {
x=x+xv;
y=y+yv;
}
public void gravity(Planet[] objects,float intensity) {
Planet planet;
float distancec;
float gravity;
for (Planet obj:objects) {
if (obj != null) {
if (obj.equals(this)==false) {
planet=obj;
distancec=distance(planet);
gravity=distancec*(planet.w/intensity);
xv=xv+((x-planet.x)*gravity);
yv=yv+((y-planet.y)*gravity);
if (distancec < w+planet.w) {
//Probably bump off or unite...
}
}
}
else {
break;
}
}
}
}
public class Gravity extends JFrame implements MouseListener, KeyListener, MouseWheelListener {
public int[] mouse=new int[5];
public Planet[] planets=new Planet[100];
public void mousePressed(MouseEvent m) {
if (m.getButton() == m.BUTTON1) {
mouse[2]=1;
}
if (m.getButton() == m.BUTTON1) {
mouse[4]=1;
}
}
public void mouseClicked(MouseEvent m) {
if (m.getButton() == m.BUTTON1) {
mouse[2]=3;
}
if (m.getButton() == m.BUTTON1) {
mouse[4]=3;
}
}
public void mouseReleased(MouseEvent m) {
if (m.getButton() == m.BUTTON1) {
mouse[2]=2;
}
if (m.getButton() == m.BUTTON1) {
mouse[4]=2;
}
}
public void mouseEntered(MouseEvent m) {
}
public void mouseExited(MouseEvent m) {
}
public void mouseWheelMoved(MouseWheelEvent w) {
mouse[3]=w.getWheelRotation();
}
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e) {
}
public Gravity(){
super("Gravity");
requestFocus();
addKeyListener(this);
addMouseListener(this);
setTitle("Gravitation");
setContentPane(new Zeichenflaeche());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setResizable(true);
setVisible(true);
while (true){
repaint();
try {
Thread.sleep(33);
} catch(InterruptedException bug) {
Thread.currentThread().interrupt();
System.out.println(bug);
}
mouse[0]=MouseInfo.getPointerInfo().getLocation().x-getComponents()[0].getLocationOnScreen().x;
mouse[1]=MouseInfo.getPointerInfo().getLocation().y-getComponents()[0].getLocationOnScreen().y;
repaint();
}
}
class Zeichenflaeche extends JPanel{
public boolean dragging;
public float w;
public Zeichenflaeche() {
}
public void reset_mouse_state() {
mouse[2]=0;
mouse[3]=0;
mouse[4]=0;
}
public void paintComponent(Graphics g){
if (mouse[2]==1) {
dragging=true;
}
if (dragging==true) {
w++;
}
if (mouse[2]==2 || mouse[2]==3) {
dragging=false;
System.out.println("Append Planet");
for (Planet planeti:planets) {
if (planeti == null) {
planeti=new Planet(mouse[0],mouse[1],w,0,0);
System.out.println("Planet succesfully appended");
System.out.println(Arrays.toString(new float[] {planeti.x,planeti.y,planeti.w}));
break;
}
}
w=1;
}
for (Planet planeti:planets) {
try {
g.setColor(Color.GREEN);
g.fillOval((int)planeti.x-(int)planeti.w,(int)planeti.y-(int)planeti.w,(int)planeti.w*2,(int)planeti.w*2);
planeti.gravity(planets,10);
planeti.move();
}
catch (Exception bug) {
}
}
reset_mouse_state();
}
}
public static void main(String args[]){
new Gravity();
}
}
。这些数量可能与您分配给OUTRES
数组的55个变量不匹配。
如果您希望SAS创建新变量,那么您最常列出它们或者至少告诉SAS应该有多少变量。以下是一些应该有效的例子。
RES
答案 1 :(得分:0)
尝试更改
array outres _numeric_;
到
array outres[*] _numeric_;