我正在使用下面的代码创建7个不同的表(tmp1,tmp2 ... tmp7)。每个acc表都有相同的列和名称,唯一的区别是每个表都在不同的库中(test1,test2 ... test7)。有可能做一些循环,而不是输入7次以下的代码吗?
public class NewWork
{
public JFrame Frame;
public JLabel textLabel;
public JButton readButton, writeButton, printButton;
public JTextField textField;
public FileReader reader;
public FileWriter writer;
public BufferedReader br;
public BufferedWriter bw;
public void PrintFrame()
{
Frame = new JFrame();
Frame.setSize(500, 300);
//Frame.pack();
Frame.setBackground(Color.BLUE);
textLabel = new JLabel();
textLabel.setText("Selected File Path:");
textLabel.setBounds(30, 30, 300, 30);
textLabel.setVisible(true);
textField = new JTextField();
textField.setBounds(30, 70, 300, 30);
textField.setVisible(true);
readButton = new JButton();
readButton.setBounds(350, 70, 100, 30);
readButton.setText("Select File");
readButton.setVisible(true);
readButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser FileChooser = new JFileChooser();
FileChooser.showOpenDialog(null);
File f= FileChooser.getSelectedFile();
String path= f.getAbsolutePath();
try
{
reader = new FileReader(path);
br = new BufferedReader(reader);
textField.read(br, null);
br.close();
textField.requestFocus();
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null, e1);
// Check Later
JOptionPane.showMessageDialog(FileChooser, e1);
}
}
});
writeButton = new JButton();
writeButton.setBounds(30, 130, 100, 30);
writeButton.setText("Write");
writeButton.setVisible(true);
writeButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
writer = new FileWriter("E://new.txt");
bw = new BufferedWriter(writer);
textField.write(bw);
bw.close();
textField.setText("");
textField.requestFocus();
}
catch(Exception e2)
{
JOptionPane.showMessageDialog(null, e2);
}
}
});
printButton = new JButton();
printButton.setBounds(190, 130, 100, 30);
printButton.setText("Print Setup");
printButton.setVisible(true);
printButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try
{
boolean complete = textField.print();
if(complete)
{
JOptionPane.showMessageDialog(null, "Done Printing!");
}
else
{
JOptionPane.showMessageDialog(null, " Printing!");
}
}
catch(Exception e3)
{
JOptionPane.showMessageDialog(null, e3);
}
}
});
Frame.add(textLabel);
Frame.add(textField);
Frame.add(readButton);
//Frame.add(writeButton);
Frame.add(printButton);
Frame.setLayout(null);
Frame.setLocationRelativeTo(null);
Frame.setVisible(true);
Frame.setResizable(false);
//
}
public static void main(String[] args)
{
NewWork nw = new NewWork();
nw.PrintFrame();
//System.out.println("Hi");
}
}
答案 0 :(得分:0)
这可以使用SAS Macro语言完成,该语言专为此类案例而设计。我不会进行大讨论,但以下情况应该有效。公平的警告,我没有测试这个,所以我可能在那里有一个语法错误,但如果没有别的,这应该给你一个完成解决方案的基础。
/ *宏以%macro关键字开头。宏可以采用参数,但在这种情况下不需要参数。特定于宏的命令用'%'表示。字符。 * /
%macro read_multiple_files;
%do i = 1 %to 7;
/* from this point forward, the use of '&i.' will resolve to the
appropriate loop counter 1-7 */
proc sql;
create table tmp&i. as
select *
from test&i..acc
where datepart(timestamp) in
(select max(datepart(timestamp))
from test&i..acc);
run; quit;
%end;
%mend read_multiple_files;
/* The '%mend' command doesn't really require the name of the macro to be appended, but I consider it to be good practice to include it */
/* The preceding code defines the macro program. Now to execute the job, you NEED one last command. */
%read_multiple_files;
我希望这会有所帮助。你会发现宏编程在很多实例中非常有用。这是一篇很好的白皮书。 http://www2.sas.com/proceedings/sugi29/243-29.pdf