BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wagdy
Obsidian | Level 7

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)

1 ACCEPTED SOLUTION

Accepted Solutions
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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

View solution in original post

11 REPLIES 11
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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

wagdy
Obsidian | Level 7

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.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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.
 */

wagdy
Obsidian | Level 7

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

wagdy
Obsidian | Level 7

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

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

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.  

 

 

 

Reeza
Super User

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. 

Kurt_Bremser
Super User

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

wagdy
Obsidian | Level 7

Many thanks. Very helpful suggestions. Regards

Astounding
PROC Star

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 1364 views
  • 1 like
  • 5 in conversation