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

I'm writing a macro to allow a user to select a subset of columns in a data table by name and then produce summaries appropriate to the type of the data in the column. The first step is to create a data set with the appropriate names to control a call execute routine. It looks like the following:

 

data varData;
length varnames $20 vardisplays $20;
infile datalines dlm = ",";
input varnames $ vardisplays $;
datalines;sodium, Sodium (Na);

Here, varnames will be the names of the columns in the data set to summarize and vardisplays will be a (possibly long) string to describe the variable. But, I have the following issue:

 

proc sql;
	select * from varData where varnames = "sodium";
quit;

This does not return any rows, even though there's a clearly a "sodium" in the varnames column. This is a problem, because I'll later need to join this data table with sashelp.vcolumn to get the data type of the column in question.

 

Now, this is where it gets really fun. I ran that example on sas studio version 3.8 and got the behavior I described above. I then went and ran it on the desktop version and it behaved as expected, that is, it gave me the observation. 

 

Does anyone know what the heck is going on with sas studio here?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Make sure there are not "invisible" characters in either your data lines or your WHERE statement.

Common characters that to not print any ink on the page are: 

09 - Tab

0A - Linefeed

0D - Carriage Return

A0 - "non-breaking" space

00 - null

 

You can use the $HEX format to see the actual codes of the characters in the strings.

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

What does you SAS log say for the data step? How many lines did it read? How many observations did it write?

 

It does not look like you gave it any lines of data.

Your data step should look like this:

data varData;
  length varnames $20 vardisplays $20;
  infile datalines dlm = ",";
  input varnames $ vardisplays $;
datalines;
sodium, Sodium (Na)
;

Notice how the lines of data start in column 1.  Notice how the data lines ending is marked by a line with a semi-colon on it.  You don't need that extra RUN: statement between your data step and your PROC step.  It doesn't hurt anything, other than to confuse novice SAS programmers into thinking the data step continues beyond the data lines.

icrandell
Obsidian | Level 7

Tom,

 

my apologies, that was a copying error when I brought my code into the reply box. I did have the code spaced as you did in your reply. When I ran the data step the log reports:

 

74         data varData;
 75         length varnames $20. vardisplays $20.;
 76         infile datalines dlm = ",";
 77         input varnames $ vardisplays $;
 78         datalines;
 
 NOTE: The data set WORK.VARDATA has 1 observations and 2 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.01 seconds
       cpu time            0.01 seconds

 The output data tab also shows a 1x2 table with the data as I entered it. When I run the proc sql afterwards, the log reports:

 74         proc sql;
 75         select * from varData where varnames = "sodium";
 NOTE: No rows were selected.
 76         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.03 seconds
       cpu time            0.03 seconds

This code also works completely as expected when I run it without modification on the desktop version of sas, which is 9.4 by the way. I can confirm that there are no syntax errors or typos of any kind. This appears to be purely SAS studio issue.

Tom
Super User Tom
Super User

Make sure there are not "invisible" characters in either your data lines or your WHERE statement.

Common characters that to not print any ink on the page are: 

09 - Tab

0A - Linefeed

0D - Carriage Return

A0 - "non-breaking" space

00 - null

 

You can use the $HEX format to see the actual codes of the characters in the strings.

icrandell
Obsidian | Level 7

The hex solution did it. It turns out there was a leading tab, which I had used to align the text. Frustrating that sas studio seemed to include the leading tab where sas desktop did not. 

Tom
Super User Tom
Super User

You can change the editor preference to have it insert spaces instead of literal tab characters.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 575 views
  • 0 likes
  • 2 in conversation