BookmarkSubscribeRSS Feed
wlierman
Lapis Lazuli | Level 10

Hello,

 

I wanted to follow up on the code solution that you provided earlier on this question.  I am still trying to step through the why it works.  But I did run into problem.  I decided to go the overkill route and made it this far

Data OPERA.OPERA_All_2;
        call streaminit(45);
		length obs 8.;
		array vars(*) $3. DLEAdi DMHDdi DCOMdi DEARdi DEYEdi DDRSdi DOUTdi DREMdi DPHYdi;

		do obs= 1 to 200; *181308;

		         do i=1 to dim(vars);
				         vars(i)= put(rand('table', 0.4, 0.4, 0.2), Z3.);
						 if vars(i) = '003' then call missing(vars(i));
				 end;
				 output;
		end;
		drop i;
run;

*set input data set  name;
%let INPUT_DSN = OPERA.OPERA_All_2;
%let OUTPUT_DSN = OPERA.OPERA_All_2A;
* create format for missing;

proc format;
  value $ missfmt ' ' = "Missing"  other = "Not_Missing";
  value nmissfmt . ="Missing" other="Not_Missing";
run;

* proc freq to count missing / non-missing;
ods select none;
* turns off the output so the results sdo not get too messy;

proc freq data=&INPUT_DSN.;
    table _all_ / missing;
	format _numeric_ nmissfmt. _character_ $missfmt.;
run;

ods select all;
* Format output;   

Data OPERA.OPERA_ALL_2_A;
   length Variable $32.  Variable_Value  $50.;
   set OPERA.OPERA_ALL_2;
   Variable=scan(table, 2);
   Variable_Value=strip(trim(vvaluex(variable)));
   presentation = catt(frequency, " (", trim(put(percent/100, percent7.1)), ")");
   keep Variable Variable_Value frequency percent cum: presentation;
   label Variable='Variable' Variable_Value='Variable_Value';
run;

Then I ran into this error in the log


NOTE: Argument to function VVALUEX is not a valid variable name:  .
NOTE: Argument to function VVALUEX is not a valid variable name:  .
NOTE: Argument to function VVALUEX is not a valid variable name:  .
NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      200 at 274:57
NOTE: There were 200 observations read from the data set OPERA.OPERA_ALL_2.
NOTE: The data set OPERA.OPERA_ALL_2_A has 200 observations and 4 variables.
NOTE: Compressing data set OPERA.OPERA_ALL_2_A increased size by 100.00 percent.
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds


278  proc sort Data = OPERA.OPERA_ALL_2;
279     by Variable;
ERROR: Variable VARIABLE not found.

The log window filled up with the Note:  Argument to function VValueX .......

I have 181,000 obs so I pared it down to 200 just for testing.  I still ran into the note in the log.

 

In the first section of code,

Also I tried to explore with formats how I can substitute the text 'No' 'Yes' or 'Missing' for the '001', '002', '003' variables (which I couldn't pull off) but then noticed that the '001' etc didn't match up with the actual occurrence of the character values in the dataset.  That is, if '001' = No  and '002' = Yes  and '003' = missing  that they weren't aligning with the actual data.  That is if the dataset had in row 1       No    No    No    Yes     .     No    No

that the var codes might be                                     001  002   001   003   002  002   001

(that is hypothetical example but it illustrates the issue). And it might be my lack of connecting the pieces of the code?

 

Thank you for your initial help, and I hope that you can guide me through this.  I use some of your code solutions for months and they work like a charm.

Thank you.

 

wklierman

 

 

 

 

4 REPLIES 4
Tom
Super User Tom
Super User

You left something out somewhere.

Your current code is not generating any output from PROC FREQ.

Did you forget the ODS OUTPUT statement?

wlierman
Lapis Lazuli | Level 10

You are right.

 

I did forget the proc freq step.

 

Thank you.

Kurt_Bremser
Super User

You are using variables that are not in the input dataset:

 89         Data myfold.OPERA_ALL_2_A;
 90            length Variable $32.  Variable_Value  $50.;
 91            set myfold.OPERA_ALL_2;
 92            Variable=scan(table, 2);
 93            Variable_Value=strip(trim(vvaluex(variable)));
 94            presentation = catt(frequency, " (", trim(put(percent/100, percent7.1)), ")");
 95            keep Variable Variable_Value frequency percent cum: presentation;
 96            label Variable='Variable' Variable_Value='Variable_Value';
 97         run;
 
 NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
       92:18   
 NOTE: Variable table is uninitialized.
 NOTE: Variable frequency is uninitialized.
 NOTE: Variable percent is uninitialized.
 WARNING: The variable cum: in the DROP, KEEP, or RENAME list has never been referenced.
 NOTE: Argument to function VVALUEX is not a valid variable name:  .

Since table is not there, a SCAN() from it will create an empty string, which can't be used as argument for the VVALUEX() function.

I guess you missed to use ODS OUTPUT to create a dataset from the FREQ output, to use that as input in this data step.

wlierman
Lapis Lazuli | Level 10

Hello,

 

I did forget the proc freq step.

 

Thank you.

 

 

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 659 views
  • 2 likes
  • 3 in conversation