I created the following RELGP 1-9
if RELIG=0 then RELGP= 1; /*NOR*/
if RELIG=1 then RELGP= 2; /*CH*/
if RELIG=2 then RELGP= 3; /*MU*/
if RELIG=3 then RELGP= 4; /*JE*/
if RELIG=4 then RELGP= 5; /*HIN*/
if RELIG=5 then RELGP= 6; /*SIK*/
if RELIG=6 then RELGP= 7; /*ZAS*/
if RELIG=9 then RELGP= 8; /*ALH*/
if RELIG=10 then RELGP= 9; /*BAH*/
I would like to lump together the responses of the RELGP 5,6,7,8 &9 into one variable to be able to compare them to THE other variables Relgp1, Relgp2, Relgp3, Relgp4
I.e. want to end with 5 groups (variables) instead of 9 groups sited below
What to do? Many thanks. Would appreciate any help. Wagdy. (WML@QUEENSU.CA)
Try this
if RELIG=0 then RELGP= 1; /*NOR*/
if RELIG=1 then RELGP= 2; /*CH*/
if RELIG=2 then RELGP= 3; /*MU*/
if RELIG=3 then RELGP= 4; /*JE*/
if RELIG in (4, 5..6 9, 10) then RELGP= 5; /*HIN, SIK, ZAS, ALH, BAH*/
i
Try this
if RELIG=0 then RELGP= 1; /*NOR*/
if RELIG=1 then RELGP= 2; /*CH*/
if RELIG=2 then RELGP= 3; /*MU*/
if RELIG=3 then RELGP= 4; /*JE*/
if RELIG in (4, 5..6 9, 10) then RELGP= 5; /*HIN, SIK, ZAS, ALH, BAH*/
i
Many thanks. Your suggestion worked.
One more Q. How to initialize a variable. Regards.
Variable RELGP1 is uninitialized.
NOTE: Variable RELGP2 is uninitialized.
NOTE: Variable RELGP3 is uninitialized.
NOTE: Variable RELGP4 is uninitialized.
NOTE: Variable RELGP5 is uninitialized.
NOTE: Variable RELGP6 is uninitialized.
NOTE: Variable RELGP7 is uninitialized.
Your original question did not include sample data. When you submit a question it helps the community by suppling a small set of sample data and the code you are having an issue with. I can not answer your question without more detailed information such as SAS code, sample data that represents your question and the SAS code your are providing and what you are trying to archive in the final outcome.
/*
*
*If your question has been solved then you
* should mark the those answers as approved solutions for the
* answer that solved your original question. That would give
* credit to the individual that solved your question and it
* closes unanswered question in the SAS communities Q.
*/
Thank you for your prompt response. very sorry. I am not competent in SAS program.
I created RELGP 1, 2, 3, 4 & 5 from RELIG 0, 1, 2, 3, & then lumped together RELIG 4, 5, 6, 9 & 10 in one variable called RELGP5.
I am trying to run ANOVA to compare these groups responses on a scale.
241 if RELIG=0 then RELGP= 1;
242 if RELIG=1 then RELGP= 2;
243 if RELIG=2 then RELGP= 3;
244 if RELIG=3 then RELGP= 4;
245 if RELIG in (4, 5,6, 9, 10) then RELGP= 5;
I got the following comments on the log:
NOTE: Variable RELGP1 is uninitialized.
NOTE: Variable RELGP2 is uninitialized.
NOTE: Variable RELGP3 is uninitialized.
NOTE: Variable RELGP4 is uninitialized.
I WOULD LIKE TO KNOW HOW TO INTIALIZE A VARIABLE. Best regards
You are only showing us part of the code. You probably have a length or format statement including those variables.
Many thanks. I did not want to bore you with the whole program. all what I need to know is how to initialize a variable. regards
you could use:
for a number
retain Relgp 0.
or for a character
retain Relgp '';
it could be intitialized by the input statement like this
input @1 name $25.
or
input @1 a_number 8.
the list go on and on. Need your sample data and how you are accessing the data to tell clearly.
hope this helps
Please when posting help us by helping yourself with full details explaining the request including sample data and code you are trying to get to work. It is hard to tell with such little information it becomes a guessing game.
Showing the whole program is not a 'bore', in fact, not showing it causes more issues because of the guessing and attempts at all types of explanation when it would be significantly faster to say, you miss understood XYZ or mistyped ABC. Please understand, sincerely, not showing code isn't doing you any favours.
@wagdy wrote:
Many thanks. I did not want to bore you with the whole program. all what I need to know is how to initialize a variable. regards
Variables in SAS are not 'initialized' like in other languages. The error means you're attempting to use a variable somewhere and it has all missing values so SAS tells you it has no values or is not 'initialized'. Usually it means you've misspelled a variable but since you won't show the code we cannot offer any further advice. There can be other reasons beyond this why that error message can appear but listing them all would take a lot of effort.
A typical case for the "uninitialized" NOTE is this:
27 data test; 28 length xx1 $4; 29 x1 = "ABCD"; 30 run; NOTE: Variable xx1 is uninitialized. NOTE: The data set WORK.TEST has 1 observations and 2 variables.
Note the typo in the length statement. For the data step compiler this means it defines a variable that is neither read from any input, used on the left side of an assignment, or used in a call routine (where it might get a value). Since this is a mistake on the part of the programmer in 99% of cases, the data step compiler alerts you to it.
Your original code can be greatly reduced by using a select() statement:
select (relig);
when (0,1,2,3,4,5,6) relgp = relig + 1;
when (9,10) relgp = relig - 1;
end;
I deliberately used no otherwise branch, so you get an ERROR when an unexpected value is encountered.
Another method would be to use an informat:
proc format;
invalue myfmt
0 = 1
1 = 2
2 = 3
4 = 5
5 = 6
6 = 7
9 = 8
10 = 9
;
run;
data test;
input relig;
relgp = input(put(relig,best.),myfmt.);
cards;
0
1
2
3
4
5
6
9
10
;
run;
The put() is just there to avoid the automatic type conversion and the corresponding NOTE in the log (Maxim 25).
Edit: fixed a typo
Many thanks. Very helpful suggestions. Regards
The code you showed applies to RELGP.
The note about variables being uninitialized is unrelated to RELGP. It relates to RELGP1, RELGP2, RELGP3, RELGP4, and RELGP5. At least show the portion of the program that refers to those names.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.