BookmarkSubscribeRSS Feed
keckk
Fluorite | Level 6
Hello all!

I use two different SAS versions (9.1.3 and 9.2) on different workstations and I don't know, what causes the different outputs when creating a new variable using a data step and creating formats in order to get an easily readable output by the following proc freq code.
With SAS V. 9.2. the newly created variable 'scoreWWcbd' in the data set 'score_lamecbd' is not anymore numerical but shows the assigned value labels ('sound', 'uneven' etc), neither is the variable 'origin' not anymore a numerical one (1, 2, 3, 4) but a string variable ('CH RHxSi' ....). The output tables shows the assigned value labels.
Log says: Format originfmt. has been output
Format scoreWWcbd. has been output

With SAS V. 9.1.3 the codes in the order given below work fine (assigned value labels in the output tables, but not in the new data set).

proc format;
value scoreWWcbd 0='sound' 1='uneven' 2='lame';
value originfmt 1='CH RHxSi' 2='NZL HF' 3='CH BV' 4='CH HF';
run;
data scores_lamecbd;
set scores_lame;
if 1 <= score_WW <=1.5 then scoreWWcbd=0;
if 2 <= score_WW <=2.5 then scoreWWcbd=1;
if 3 <= score_WW <=5 then scoreWWcbd=2;
format origin originfmt. scoreWWcbd scoreWWcbd.;
drop score_tr score_jflex score_barch;
run;
proc freq data= scores_lamecbd;
title 'frequency counts of .... scores';
tables scoreWWcbd origin
origin*scoreWWcbd;
run;

If I run the data step first (in SAS V. 9.2), and afterwards the proc format code followed by proc freq code, the new data set looks fine ('origin' and 'scoreWWcbd' still numerical variables), but the tables output does not show up with the assigned value labels, but only with the initial numbers for the levels of 'origin' and 'scoreWWcbd'.
The log gives a Note: Format originfmt. has been output
Format scoreWWcbd. has been output.

Does anyone know what could be the mistake behind this ?
Thanks for any input,
keck hmm, there seems to be a limit in lines ?
this is the missing part of my message:
if 1 <= score_WW <=1.5 then scoreWWcbd=0;
if 2 <= score_WW <=2.5 then scoreWWcbd=1;
etc
format origin originfmt. scoreWWcbd scoreWWcbd.;
drop score_tr score_jflex score_barch;
run;
proc freq data= scores_lamecbd;
title 'frequency counts of .... scores';
tables scoreWWcbd origin origin*scoreWWcbd;
run;

If I run the data step first (in SAS V. 9.2), and afterwards the proc format code followed by proc freq code, the new data set looks fine ('origin' and 'scoreWWcbd' still numerical variables), but the tables output does not show up with the assigned value labels, but only with the initial numbers for the levels of 'origin' and 'scoreWWcbd'.

The log gives the same note as above.
Does anyone know what could be the mistake behind this ?
Thanks for any input,
keck


Message was edited by: keckk
5 REPLIES 5
keckk
Fluorite | Level 6
hmm, there seems to be a limit in lines ...? here's the second part of my message:
if 1 <= score_WW <=1.5 then scoreWWcbd=0;
if 2 <= score_WW <=2.5 then scoreWWcbd=1;
if 3 <= score_WW <=5 then scoreWWcbd=2;
format origin originfmt. scoreWWcbd scoreWWcbd.;
drop score_tr score_jflex score_barch;
run;
proc freq data= scores_lamecbd;
title 'frequency counts of .... scores';
tables scoreWWcbd origin origin*scoreWWcbd;
run;

If I run the data step first (in SAS V. 9.2), and afterwards the proc format code followed by proc freq code, the new data set looks fine ('origin' and 'scoreWWcbd' still numerical variables), but the tables output does not show up with the assigned value labels, but only with the initial numbers for the levels of 'origin' and 'scoreWWcbd'.
The log gives a Note: Format originfmt. has been output...

Does anyone know what could be the mistake behind this ?
Thanks for any input,
keck
keckk
Fluorite | Level 6
Now hopefully using the right markups, the whole message will appear ...

Hello all!

I use two different SAS versions (9.1.3 and 9.2) on different workstations and I don't know, what causes the different outputs when creating a new variable using a data step and creating formats in order to get an easily readable output by the following proc freq code.
With SAS V. 9.2. the newly created variable 'scoreWWcbd' in the data set 'score_lamecbd' is not anymore numerical but shows the assigned value labels ('sound', 'uneven' etc), neither is the variable 'origin' not anymore a numerical one (1, 2, 3, 4) but a string variable ('CH RHxSi' ....). The output tables shows the assigned value labels.
Log says:
Format originfmt. has been output
Format scoreWWcbd. has been output

With SAS V. 9.1.3 the codes in the order given below work fine (assigned value labels in the output tables, but not in the new data set).

proc format;
value scoreWWcbd 0='sound' 1='uneven' 2='lame';
value originfmt 1='CH RHxSi' 2='NZL HF' 3='CH BV' 4='CH HF';
run;
data scores_lamecbd;
set scores_lame;
if 1 <= score_WW <=1.5 then scoreWWcbd=0;
if 2 <= score_WW <=2.5 then scoreWWcbd=1;
if 3 <= score_WW <=5 then scoreWWcbd=2;
format origin originfmt. scoreWWcbd scoreWWcbd.;
drop score_tr score_jflex score_barch;
run;
proc freq data= scores_lamecbd;
title 'frequency counts of .... scores';
tables scoreWWcbd origin origin*scoreWWcbd;
run;

If I run the data step first (in SAS V. 9.2), and afterwards the proc format code followed by proc freq code, the new data set looks fine ('origin' and 'scoreWWcbd' still numerical variables), but the tables output does not show up with the assigned value labels, but only with the initial numbers for the levels of 'origin' and 'scoreWWcbd'.
The log gives a Note:
Format originfmt. has been output...

Does anyone know what could be the mistake behind this ?
Thanks for any input,
keck
Cynthia_sas
SAS Super FREQ
Hi:
I'm not entirely sure I understand your question and I no longer have SAS 9.1.3 to test with. However, I am fairly certain that format handling has not changed between SAS 9.1.3 and SAS 9.2. I also do not understand what you mean when you say that "tables output does not show up with the assigned value labels, but only with the initial numbers for the levels of 'origin' and 'scoreWWcbd'".

Consider the program below. In it I have 2 formats...one numeric format (AGEF) that will be used with the numeric variable AGE to split my obs into Driver and Non-driver categories. Then I have another numeric format (ALTAGE) that can also be used to split my studnets into either Pre-Teen or Teenager categories.

After I create WORK.CLASS and permanently assign the AGEF format to the AGE variable, I run a PROC CONTENTS to show that the AGE variable is still numeric, but the permanently assigned format AGEF will be used to DISPLAY (and only display) the values of AGE in all procedures that use formats.
[pre]

proc format;
value agef 11-14 = 'Not Driving'
15-High = 'Driving Age';

value altage 11-12 = 'Pre-Teen'
13-19 = 'Teenager';
run;

data class;
set sashelp.class;
format age agef.;
run;
title; footnote;
ods listing close;

ods html file='c:\temp\fmtques.html' style=sasweb;

ods html select variables;
proc contents data=class;
title '1) Note that AGE is still a NUMERIC variable';
run;

proc freq data=class;
title '2) Now the AGEF format is automatically used in PROC FREQ';
tables age;
run;

proc freq data=class;
title '3) Here, the ALTAGE format is used for AGE variable';
tables age;
format age altage.;
run;

proc freq data=class;
title '4) Note that NO format is used because "null" format statement removes any format for age';
tables age;
format age;
run;
ods _all_ close;
[/pre]

So, for Report #2, the PROC FREQ does not need a FORMAT statement and the user-defined format AGEF will be used to the frequency table. But, in Report #3, when I use the explicit FORMAT statement to associate AGE with the ALTAGE format, the output now shows the new categories being used. Then in Report #4, with a "null" format statement, I am instructing PROC FREQ to bypass the use of the formatted values for the AGE variable and to just show me the ages without any format being applied.

It looks to me as though you are trying to use numeric values to create a new numeric value (scoreWWcbd) and then have a label used for the new values of scoreWWcbd. One thing you could do is use a format to create your new variable. You could create your scoreWWcbd without using IF statements -- just by using a user-defined format. See the program at the end of the post. It uses a format to create a new numeric variable (NUMVAR) and a new character variable (CHARVAR) from score_WW. Note, how, in the PROC PRINT output, the value for Dave shows up as 6 for both CHARVAR and NUMVAR, because my user-defined format did not account for a value of 6 in the format definition (I suspect, but am not sure, that this behavior might be what you are seeing in your format usage.)


If you really believe you have an issue between SAS 9.1.3 and SAS 9.2, then your best resource is to work with Tech Support.

cynthia
[pre]
proc format;
value scWW
1-1.5 = '0'
2-2.5 = '1'
3-5 = '2';

value altsc
1-1.5 = 'sound'
2-2.5 = 'uneven'
3-5 = 'lame'
other = 'unknown value outside range';
run;

data testfmt;
infile datalines;
input name $ score_WW;
charvar = put(score_WW,scww.);
numvar = input(charvar,best2.);
return;
datalines;
alan 1.3
barb 2.4
carl 4.0
dave 6.0
;
run;

ods listing close;

ods html file='c:\temp\fmt_make_vars.html' style=sasweb;;

ods html select variables;
proc contents data=testfmt;
title 'Check the different types for charvar and numvar';
run;

proc print data=testfmt;
title 'Notice how charvar and numvar are set based on value for score_WW -- without IF statements';
run;

proc freq data=testfmt;
tables score_ww;
format score_ww altsc.;
run;

ods _all_ close;
title; footnote;

[/pre]
keckk
Fluorite | Level 6
Thanks very much Cynthia@sas for your details and the codes, which have teached me new things about what you can do with formats (especially the "null" format statement).

Yes, you were right, I tried to use my numeric variable score_WW to create a new numeric value (scoreWWcbd) i.e. I combined the initial scores to have only 3 scores anymore (0, 1, 2), and then have a value label used to only display the new values of scoreWWcbd in the output frequency tables. The new score will be used in subsequent procedures (proc glimmix in SAS 9.2), that's why I wanted to retain the variable as a numeric in the new data set.

The odd thing about my codes is, that with SAS 9.1.3 the data step creating the new variable with if statements (see posted code) ignores the format statement so that in the new data set work.scores_lamecbd the new score is still numeric (which is fine) and I obviously do not seem to need the format statements in the following proc freq code to show the labels (defined in the proc format code) in the tables output,
BUT with SAS 9.2 the data step DOES assign the user-defined formats for 'origin' and 'scoreWWcbd' to the data set (which is not undesired because of subsequent analysis in proc glimmix), which will be then used to display the values of 'origin' and 'scoreWWcbd' in the tables output as well (without using format statements in proc freq again)....still, there seems to be a little difference in the two SAS versions.

Anyway, with your help I hopefull know how to handle it in the future

Cheers,
Karin
Cynthia_sas
SAS Super FREQ
Hi:
I'm glad that my example was able to help you.

As for your assertion that the FORMAT statement works differently in SAS 9.1.3 versus SAS 9.2, I have a very hard time understanding how this could have happened. It might be a syntax error in the SAS 9.1.3 code (such as a missing semicolon, that rendered the FORMAT statement unrecognizable) and that syntax error got fixed in SAS 9.2 ... however, all the way back to when I started using SAS (a LONG time ago), whenever I have used a FORMAT statement in a DATA step program, the format has ALWAYS been used for my variables because using the FORMAT statement in a DATA step program causes the association between the variable and the format to be made in the descriptor portion of the SAS dataset. That is a fundamental SAS behavior and so differences in the FORMAT statement behavior between SAS 9.1.3 and SAS 9.2 are just not anything that I have seen.

So, while I don't want to dismiss your assertion, there's no way I can duplicate your observed behavior definitively. If you want to pursue this issue of an observed difference in FORMAT behavior between SAS 9.1.3 and SAS 9.2, this is the type of issue that would be best taken up with SAS Technical Support.

cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 1248 views
  • 0 likes
  • 2 in conversation