BookmarkSubscribeRSS Feed
R_A_G_
Calcite | Level 5
hello,

I took Doc's advice and changed the title, I have also took Scott's suggestion and used: PUTLOG _ALL_;

one thing that Scott did not mention was that using STOP after PUTLOG will stop that part of my program and nothing will happen afterward. So I ended up using only PUTLOG_ALL_;

now my problem is I want to use CALL CATX function: to replace "+" with " " (space)

my data is the following:
L1_0+L1_13+L1_14

I need to Remove the "+" (addition sign), replace it with blank " " and label the column MAIN to look like this in the column named MAIN

L1_0 L1_13 L1_14

The LOG result:
NewParmAdd=L1_0+L1_13+L1_14 Main=L1_13 L1_14

NewParmAdd=L1_0+L1_13+L1_14
Main=L1_13 L1_14

This is the code I am using:

%let numitem=10;
%let numatt=4;

CALL CATX(" ", Main, OF L1_11--L&numitem._1&numatt.);

As you see the the old data (column) called NewParmAdd has L1_0+L1_13+L1_14 and the new data(column) called MAIN has only L13 L1_14 while I wanted to have L1_13 L1_14 and L1_0

Thank you
R.A.G.
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Look at the TRANSLATE function to manipulate your MAIN variable, I suppose.

Honestly, you're spoon-feeding information making it difficult to assist you --- paste the SASLOG intact with your code as well as SAS diagnostics revealed (COPY and PASTE).

Scott Barry
SBBWorks, Inc.
R_A_G_
Calcite | Level 5
Hi Scott;

This is the part of log that relates to the code:
Thank you


LOG:
NewParmAdd=L3_0+L3_13+L3_14 Main=L3_13 L3_14 OrderMain= Order12way= Order22way= Order13way=
Order23way= Order33way= OrderMainMax= Order12wayMax= Order22wayMax= Order13wayMax=
Order23wayMax= Order33wayMax= class=16 item=3 scorepattern=30011 thresh=4 attpattern=0011
classatt1=1 classatt2=1 classatt3=1 classatt4=1 itematt1=0 itematt2=0 itematt3=1 itematt4=1
scoreatt1=0 scoreatt2=0 scoreatt3=1 scoreatt4=1 BeginS=. G_11=G_11 G_12=G_12 G_13=G_13 G_14=G_14
EndS=. LongSParm=19 BeginI=. LInt=L3_0 L1_11= L2_11= L3_11= L4_11= L5_11= L6_11= L7_11=
L8_11= L9_11= L10_11= L11_11= L12_11= L13_11= L14_11= L15_11= L1_12= L2_12= L3_12=
L4_12= L5_12= L6_12= L7_12= L8_12= L9_12= L10_12= L11_12= L12_12= L13_12= L14_12=
L15_12= L1_13= L2_13= L3_13=L3_13 L4_13= L5_13= L6_13= L7_13= L8_13= L9_13= L10_13=
L11_13= L12_13= L13_13= L14_13= L15_13= L1_14= L2_14= L3_14=L3_14 L4_14= L5_14= L6_14=
L7_14= L8_14= L9_14= L10_14= L11_14= L12_14= L13_14= L14_14= L15_14= LastI=.
LongIParm=16 LongOrderMain=. _ERROR_=0 _N_=33

This is the code:
%MACRO Equations (structorder, maxitemorder);


%let num_skills=4;
%let numatt=4;
%let numitem=%eval(2**&num_skills-1);
%let numclass=%eval(2**&num_skills);
%let IDname=num_student;
%let numatt=&num_skills; /*change it to what ever value for skill*/


DATA kernel;
/* Listing all character variables eventually created*/
LENGTH NewStruc NewStrucAdd NewParm NewParmAdd
Main OrderMain Order12way Order22way
Order13way Order23way Order33way
OrderMainMax Order12wayMax Order22wayMax
Order13wayMax Order23wayMax Order33wayMax $500;

SET kernel;
/*** STRUCTURAL MODEL PARAMETERS*/
/* Dummy variable to use as placeholder*/
BeginS = .;
/* Main effects*/
%DO a=1 %TO &numatt.;
IF classatt&a.=1 THEN G_1&a.= "G_1&a. ";
ELSE G_1&a. = G_1&a.;
%END;

* Last variable to use as dummy place;
EndS = .;
* Creating string variables to use in NEW equations;
CALL CATX(" ", NewStruc, OF BeginS--EndS);
NewStruc = TRANWRD(NewStruc, "." , " " );
NewStruc = STRIP(NewStruc);
NewStrucAdd = TRANWRD(STRIP(NewStruc), " " , "+" );
* Creating index for longest possible number of structural parms;
LongSParm = LENGTH(STRIP(NewStruc));
run;



* Saving longest parm as new variable for class reference statement;
PROC SORT DATA=kernel; BY item DESCENDING LongSParm; RUN;


DATA SaveSLong; SET kernel; BY item;
IF FIRST.item THEN NewStrucMax=STRIP(NewStruc); ELSE DELETE; RUN;
* Merge longest parm back into data;
DATA kernel; LENGTH NewStrucMax NewStrucMaxAdd $200; MERGE SaveSLong kernel; BY item;
NewStrucMaxAdd = TRANWRD(STRIP(NewStrucMax), " " , "+" ); RUN;
* Clearing extra datasets;
PROC DATASETS LIB=WORK NOLIST; DELETE SaveSLong; RUN; QUIT;

PROC SORT DATA=kernel; BY item thresh; RUN;



* Re-opening data;
DATA kernel; SET kernel;
*** ITEM PARAMETERS;
* Dummy variable to use as placeholder;
BeginI=.;

* Intercepts per item (1);
%DO i=1 %TO &numitem.;
IF item=&i. THEN LInt = "L&i._0 ";
ELSE LInt = LInt;
%END;

* Main effects per item (up to # attributes);
%DO Num1=1 %TO &numatt.;
%DO i=1 %TO &numitem.;
IF item=&i. AND scoreatt&Num1.=1 THEN L&i._1&Num1. = "L&i._1&Num1. ";
ELSE L&i._1&Num1. = L&i._1&Num1.;
%END;
%END;


/* Last variable to use as dummy place to end series*/
LastI = .;
/* Creating string variables to use in NEW equations*/

CALL CATX(" ", NewParm, OF BeginI--LastI);
NewParm = TRANWRD(NewParm, "." , " " );
NewParm = STRIP(NewParm);
NewParmAdd = TRANWRD(STRIP(NewParm), " " , "+" );
* Creating index for longest possible number of parms;
LongIParm = LENGTH(STRIP(NewParm));
RUN;
* Saving longest parm as new variable for NEW statement;
PROC SORT DATA=kernel; BY item DESCENDING LongIParm; RUN;
DATA SaveILong; SET kernel; BY item;
IF FIRST.item THEN NewParmMax=NewParm; ELSE DELETE; RUN;
* Merge longest parm back into data;
DATA kernel; LENGTH NewParmMax $100; MERGE SaveILong kernel; BY item; RUN;
* Clearing extra datasets;
PROC DATASETS LIB=WORK NOLIST; DELETE SaveILong; RUN; QUIT;

* Creating string variables for ordering constraints;
%LET numatt1 = %EVAL(&numatt.-1);
%LET numatt2 = %EVAL(&numatt.-2);
DATA kernel; SET kernel;

* Main effects;
CALL CATX(" ", Main, OF L1_11--L&numitem._1&numatt.);
PUTLOG _ALL_;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 837 views
  • 0 likes
  • 2 in conversation