Help using Base SAS procedures

Spurious asterisks in *.txt output file

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Spurious asterisks in *.txt output file

Greetings,

 

I am attempting to export a SAS database to a space-delimited text file so that it can be imported into Mplus. I'm using SAS v9.3. Here is the code I am using:

 

data _null_ ; /* No SAS data set is created */
set work3mergem;
FILE 'H:\Andrewtxtbpio0501';
PUT subject anyboy anyboy2 anyboy3 anyboy4 rsksum rsksum2 rsksum3 rsksum4 age a2 schcom11--schcom16 c1g
c2g c3g c4g c5g c6g c7g c8g c9g c10g c1o c2o c3o c4o c5o c6o c7o c8o c9o c10o b9--b14 a8a ethgrp;
run ;

 

When I run the code, there are several asterisks in the output file instead of the values as they show in SAS (some of which are recorded values, and some of which are missing values). There are 8 asterisks in all (from a data set with 500+ observations and 1,000+ variables), and they aren't all occurring for the same variable (i.e., for one case, there's an asterisk for variable b12, for another, b14). I am having difficulty figuring out why this is happening.

 

The data set was originally saved in SPSS, and so the first step of my program is to import it to SAS. I'm including that code, too, in case that may somehow be part of the problem:

 

libname inlib spss 'H:\Research\Huebner Paper HIV\FINAL DASH DATA_ONLY GOOD CASES.por';
proc convert spss=inlib out=huebhiv.dash050118;
run;

libname inlib spss 'H:\Research\Huebner Paper HIV\Oakland data_only good cases.por';
proc convert spss=inlib out=huebhiv.oakland050118;
run;

 

Any thoughts about why this might be happening and how to address it would be greatly appreciated. Thanks!

 


Accepted Solutions
Solution
‎05-30-2018 09:50 AM
Super User
Posts: 6,762

Re: Spurious asterisks in *.txt output file

Posted in reply to abarnett313

A reasonable guess:  these variables have formats connected with them, that are not wide enough.  Just remove the formats:

 

data _null_;

set work3mergem;

format _numeric_;

FILE ........

View solution in original post


All Replies
Solution
‎05-30-2018 09:50 AM
Super User
Posts: 6,762

Re: Spurious asterisks in *.txt output file

Posted in reply to abarnett313

A reasonable guess:  these variables have formats connected with them, that are not wide enough.  Just remove the formats:

 

data _null_;

set work3mergem;

format _numeric_;

FILE ........

Contributor
Posts: 23

Re: Spurious asterisks in *.txt output file

Posted in reply to Astounding

That worked! Thank you very much. 

Super User
Super User
Posts: 9,599

Re: Spurious asterisks in *.txt output file

Posted in reply to abarnett313

Without some actual data its hard to say, but I would guess that the data is formatted, and the length is not long enough to handle the format - this happens with dates for instance.  

Also how are you opening the file?  You haven't given it a file extension (.txt for instance).  Now Excel is one app that likes to show data as * which it doesn't like.  So open the file in notepadd (/++) and see what the actual output looks like.

Otherwise post some data in the form of a datastep:
https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

So we have something to work with.

 

 

Super User
Super User
Posts: 8,089

Re: Spurious asterisks in *.txt output file

Posted in reply to abarnett313

That is usually an indication that the value cannot be display using the format that is attached.  For example trying to display a 5 digit number using the 4. format.  Some SAS functionality (like PROC IMPORT and SAS/Access) have a nasty habit of attaching formats to variables even when they do not need formats attached.

 

Check if any of the variables you are trying to write have formats attached to them. For example run a PROC CONTENTS on the dataset.

 

You could just try removing all of the formats using a format statement that lists variables without any format specification.  So you could just try adding this statement to your current data _null_ step.

format _all_ ;

But then if you have any variables that contain values like date, time or datetime that needs formats to display in a human readable way you will need make sure to use formats for those.  In that case add a second FORMAT statement to re-attach formats to just those variables that need them.

Contributor
Posts: 23

Re: Spurious asterisks in *.txt output file

Thank you -- this was indeed the issue. I didn't have any variables that required special formatting, fortunately.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 130 views
  • 0 likes
  • 4 in conversation