BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Q1983
Lapis Lazuli | Level 10
Data Inventory;                            
  Set Dors_Mtg_Monthly_&Month_Minus_0.                    
    (keep = ln_no d_portfolio iv_id iv_cat_cd lm_status_cd d_lm_workout_status lm_set_up_dt bkr_status_cd      
    d_lm_workout_type lm_template_nm d_lm_workout_class                
    where = (lm_status_cd = 'A'));                      
  Days_In_LM = intck('days',lm_set_up_dt,"&EndDate."d);                  
  If Days_In_LM <= 30 Then                        
    Day_Band = 'a 0-30 Days   ';                      
  Else If Days_In_LM <= 60   Then                        
    Day_Band = 'b 31-60 Days   ';                      
  Else If Days_In_LM <= 90   Then                        
    Day_Band = 'c 61-90 Days   ';                      
  Else If Days_In_LM <= 120 Then                      
    Day_Band = 'd 91-120 Days ';                      
  Else If Days_In_LM <= 150 Then                      
    Day_Band = 'e 121-150 Days ';                      
  Else If Days_In_LM <= 180 Then                      
    Day_Band = 'f 151-180 Days ';                      
  Else If Days_In_LM > 180  Then                        
    Day_Band = 'g 181 Plus Days';                      
  if bkr_status_cd = 'A' then                        
    BK_status = 'Act BK';                        
  else BK_status = 'Non BK';                        
Run;                              
                               
sample output                            
LN_NO Days_In_LM Day_Band BK_status                      
0000755850 26 a 0-30 Days Non BK                        
0000813774 166 f 151-180 Days Non BK                        
0001059013 95 d 91-120 Days Non BK                        
0001618131 22 a 0-30 Days Non BK                        
0001721380 20 a 0-30 Days Non BK                        
0002301380 110 d 91-120 Days Non BK                        
0003428588 82 c 61-90 Days Non BK                        
0004036448 63 c 61-90 Days Non BK                        
0004116703 98 d 91-120 Days Non BK                        
0004344529 50 b 31-60 Days Non BK                        
0004851473 69 c 61-90 Days Non BK                        
0005369905 5 a 0-30 Days Non BK                        
0005441282 63 c 61-90 Days Non BK                        
0005441647 89 c 61-90 Days Non BK                        
0005705017 131 e 121-150 Days Non BK                        
0005715362 204 g 181 Plus Days Non BK                        
                               
The issue is when I apply this piece of code below to rename 'g 181 Plus Days' n to g_181_Plus_Days I get Error 214-322 Variable name ‘g 181 Plus Days’n not valid
proc transpose data = Transposed_Days_In_LM_Not_BK                    
  out = Transposed_Days_In_LM_Not_BK                      
  (keep = BK_status Total 'g 181 Plus Days'n rename = ('g 181 Plus Days'n = g_181_Plus_Days));            
  by BK_status;                          
  id Day_Band;                          
  var _freq_;                          
run;                              
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

How PROC TRANSPOSE converts the ID values to valid names depends on the setting of the VALIDVARNAME option.

Try running this program with different values for the VALIDVARNAME setting.

data have ;
  length LN_NO $10 Days_In_LM 8 Day_Band $32 BK_status $10 ;
  infile cards dsd dlm='|';
  input ln_no -- bk_status;
cards;
0000755850|26|a 0-30 Days|Non BK
0000813774|166|f 151-180 Days|Non BK
0001059013|95|d 91-120 Days|Non BK
0001618131|22|a 0-30 Days|Non BK
0001721380|20|a 0-30 Days|Non BK
0002301380|110|d 91-120 Days|Non BK
0003428588|82|c 61-90 Days|Non BK
0004036448|63|c 61-90 Days|Non BK
0004116703|98|d 91-120 Days|Non BK
0004344529|50|b 31-60 Days|Non BK
0004851473|69|c 61-90 Days|Non BK
0005369905|5|a 0-30 Days|Non BK
0005441282|63|c 61-90 Days|Non BK
0005441647|89|c 61-90 Days|Non BK
0005705017|131|e 121-150 Days|Non BK
0005715362|204|g 181 Plus Days|Non BK
;;;;
proc freq data=have ;
  tables bk_status*Day_band / noprint out=freq ;
run;
%let optsave=%sysfunc(getoption(validvarname));
options validvarname=any;
proc transpose data = freq out=want ;
  by BK_status;
  id Day_Band;
  var count;
run;
proc contents data=want;
run;
options validvarname=&optsave;

View solution in original post

3 REPLIES 3
Astounding
PROC Star

I believe it's normal for PROC TABULATE to "correct" variable names automatically when taking values from the ID statement.  Try replacing the data set options:

 

(keep = BK_status Total 'g 181 Plus Days'n rename = ('g 181 Plus Days'n = g_181_Plus_Days))

 

Try using just KEEP and see if it gets you what you are looking for:

 

(keep = BK_status Total  g: )

 

Good luck.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, that post is unreadable.  Have you posted from Excel or something.  There are grid lines everywhere, code all over.  Paste plain text and use code blocks for code (the {i} and SAS symbol above).

Tom
Super User Tom
Super User

How PROC TRANSPOSE converts the ID values to valid names depends on the setting of the VALIDVARNAME option.

Try running this program with different values for the VALIDVARNAME setting.

data have ;
  length LN_NO $10 Days_In_LM 8 Day_Band $32 BK_status $10 ;
  infile cards dsd dlm='|';
  input ln_no -- bk_status;
cards;
0000755850|26|a 0-30 Days|Non BK
0000813774|166|f 151-180 Days|Non BK
0001059013|95|d 91-120 Days|Non BK
0001618131|22|a 0-30 Days|Non BK
0001721380|20|a 0-30 Days|Non BK
0002301380|110|d 91-120 Days|Non BK
0003428588|82|c 61-90 Days|Non BK
0004036448|63|c 61-90 Days|Non BK
0004116703|98|d 91-120 Days|Non BK
0004344529|50|b 31-60 Days|Non BK
0004851473|69|c 61-90 Days|Non BK
0005369905|5|a 0-30 Days|Non BK
0005441282|63|c 61-90 Days|Non BK
0005441647|89|c 61-90 Days|Non BK
0005705017|131|e 121-150 Days|Non BK
0005715362|204|g 181 Plus Days|Non BK
;;;;
proc freq data=have ;
  tables bk_status*Day_band / noprint out=freq ;
run;
%let optsave=%sysfunc(getoption(validvarname));
options validvarname=any;
proc transpose data = freq out=want ;
  by BK_status;
  id Day_Band;
  var count;
run;
proc contents data=want;
run;
options validvarname=&optsave;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

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
  • 3 replies
  • 1847 views
  • 0 likes
  • 4 in conversation