모두에게 답변: Graph Builder에 동적 콘텐츠를 스크립팅하는 방법SAS 커뮤니티 포럼의 누군가가 이렇게 질문했습니다. 변수 개수를 미리 알지 못한 채 그래프 빌더 보고서를 생성하는 스크립트를 작성하고 싶어 했습니다. 즉, 스크립트를 작성할 때는 변수 개수를 알 수 없지만, 스크립트는 런타임에 변수 개수를 알 수 있도록 하는 것이었습니다.
원래 시도는 열에 대한 루프 안에 Graph Builder 스크립트를 포함했지만, 루프 반복마다 한 번씩 Graph Builder를 n 번 실행했습니다. 따라서 가변적인 열 개수를 고려한 단일 스크립트를 생성한 다음 해당 스크립트를 실행해야 합니다. JSL은 Expr(), Name Expr(), Eval Expr() 함수를 사용하여 이러한 유형의 메타 프로그래밍(다른 스크립트를 생성하는 스크립트)을 지원합니다. 이 함수들은 상당히 고급 함수이지만 동시에 매우 강력합니다.
먼저 대표적인 Graph Builder 보고서를 만들고 스크립트를 저장합니다.
Graph Builder(
Show Control Panel( 0 ),
Variables(
X( :Country ),
Y( :Score, Side( "Right" ) ),
Y( :Long Jump, Position( 1 ) ),
Y( :Shot Put, Position( 1 ) )
),
Elements(
Points( X, Y( 2 ), Y( 3 ), Legend( 1 ) ),
Line( X, Y( 1 ), Legend( 2 ) )
)
);
그런 다음 매개변수화하려는 부분(이 경우 Y 변수)을 기록하고 스크립트를 사용하여 런타임 정보를 기반으로 해당 부분을 만든 다음 전체 표현식에 붙입니다.
// a table with lots of columns
dt = Open( "$SAMPLE_DATA/Decathlon.jmp" );
// an expression for the graph's variables
vars = Expr( Variables( X( :Country ), Y( :Score, Side( "Right" ) ) ) );
// an expression for Points elements
points = Expr( Points( X, Jitter( 1 ) ) );
// a loop to programmitically insert variables into those expressions
first col = 4;
last col = 6;
For( i = first col, i <= last col, i++,
Insert Into( vars, Eval Expr( Y( Expr( Column( dt, i ) ), Position( 1 ) ) ) );
Insert Into( points, Eval Expr( Y( Expr( i - first col + 2 ) ) ), 1 + i - first col );
);
//Show( vars, points );
// build the Graph Builder expression from those
gb = Eval Expr(
Graph Builder(
Show Control Panel( 0 ),
Expr( Name Expr( vars ) ),
Elements( Expr( Name Expr( points ) ), Line( X, Y( 1 ) ) )
)
);
//show( gb );
gb; // execute the expression
동일한 효과를 얻는 방법이 있습니다. 비슷하지만 이해하기 더 쉬운 방법은 스크립트를 텍스트 문자열로 구성한 다음, 작업이 완료되면 Parse()와 Eval()을 호출하는 것입니다. 또 다른 방법은 Graph Builder가 이미 구성된 Graph Builder 보고서를 수정할 수 있는 'Add Variable'과 같은 메시지도 지원한다는 것입니다.
Re: 전체 답변: Graph Builder에 동적 콘텐츠를 스크립팅하는 방법이것은 작동하지만 잘못된 것입니다
- 전문가 여러분, 감사합니다!
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "col1", Numeric, Continuous, Set Formula( Col Shuffle() ) );
dt << New Column( "col2", Numeric, Continuous, Set Formula( Col Shuffle() ) );
dt << New Column( "col3", Numeric, Continuous, Set Formula( Col Shuffle() ) );
m1 = 1; m2 = 180; m0 = 10;
one=Expr(Variables( X( Transform Column( "Row", Formula( Row() ))) , Y( :height ) ));two=Expr(Elements( Position( 1, 1 ), Bar( X, Y, Legend( 5 ) ) ) );thr=Expr( Dispatch( {}, "height", ScaleBox, {Min( m1 ), Max( m2 ), Inc( m0 ), Minor Ticks( 1 )} ));
first co = 5;last col = 8;
For( i = first co, i <= last col, i++,
Insert Into( one, Eval Expr( Y( Expr( Column( dt, i ) ) ) ) );
Insert Into( two, Eval Expr(Elements( Position( 1, Expr(i-3 )), Bar( X, Y, Legend( Expr(1+i )) ) ) ));
Insert Into( thr, Eval Expr( Dispatch( {}, Column(Expr(i))<
<GET name=""></GET>
Re: 전체 답변: Graph Builder에 동적 콘텐츠를 스크립팅하는 방법전문가 여러분, 감사합니다!
JSL을 같은 방식으로 수정하려고 했지만 여전히 작동하지 않았습니다.
저는 간단한 막대형 차트를 만들고 각 막대에 동일한 상한값과 하한값을 사용했습니다.
이 동적 열 이름 지정을 완료하는 방법에 대해 전문가의 도움을 요청하시겠습니까?대단히 감사합니다!
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Column( "col1", Numeric, Continuous, Set Formula( Col Shuffle() ) );
dt << New Column( "col2", Numeric, Continuous, Set Formula( Col Shuffle() ) );
dt << New Column( "col3", Numeric, Continuous, Set Formula( Col Shuffle() ) );
m1 = 1; m2 = 180; m0 = 10;
p1 = dt << Graph Builder(
Size( 519, 841 ),
Show Control Panel( 0 ),
Show Legend( 0 ),
Show Title( 0 ),
Show Footer( 0 ),
Show X Axis( 0 ),
Show Y Axis( 0 ),
Show X Axis Title( 0 ),
Variables( X( Transform Column( "Row", Formula( Row() ) ) ), Y( :height ), Y( :weight ), Y( :col1 ), Y( :col2 ), Y( :col3 ) ),
Elements( Position( 1, 1 ), Bar( X, Y, Legend( 5 ) ) ),
Elements( Position( 1, 2 ), Bar( X, Y, Legend( 6 ) ) ),
Elements( Position( 1, 3 ), Bar( X, Y, Legend( 7 ) ) ),
Elements( Position( 1, 4 ), Bar( X, Y, Legend( 8 ) ) ),
Elements( Position( 1, 5 ), Bar( X, Y, Legend( 9 ) ) ),
SendToReport(
Dispatch( {}, "height", ScaleBox, {Min( m1 ), Max( m2 ), Inc( m0 ), Minor Ticks( 1 )} ),
Dispatch( {}, "weight", ScaleBox, {Min( m1 ), Max( m2 ), Inc( m0 ), Minor Ticks( 1 )} ),
Dispatch( {}, "col1", ScaleBox( 2 ), {Min( m1 ), Max( m2 ), Inc( m0 ), Minor Ticks( 1 )} ),
Dispatch( {}, "col2", ScaleBox, {Min( m1 ), Max( m2 ), Inc( m0 ), Minor Ticks( 1 )} ),
Dispatch( {}, "col3", ScaleBox, {Min( m1 ), Max( m2 ), Inc( m0 ), Minor Ticks( 1 )} )
)
);
