BookmarkSubscribeRSS Feed
JibJam221
Obsidian | Level 7

Hello all, im having issues with the INDSNAME column. It outputs as it should... however Im looking to make this column permanent so that I can rename the source names to more understandable terms. I tried using INDSNAME then using IF-THEN statements to rename the sources into a new column, however these sources get automatically removed once further querying the table..  is there any way for me to make INDSNAME a permanent column in the dataset?

 

data work.totaltable;
	set work.1222872-work.1222998 indsname=Dsnames;
	source=Dsnames;
	run;

data totaltable;
	set work.totaltable;
	if source='work.1222872' then SourceTransc='Transaction 2287';
......
run;
13 REPLIES 13
Reeza
Super User
data totaltable;
	set work.totaltable;
	if source='work.1222872' then SourceTransc='Transaction 2287';
......
run;

This type of coding is known to cause issues so it's a good idea to use a unique data set name between each data step, then you can trace your code for bugs. 

 

Did you check the output of totaltable after the first step to ensure that the source variable is being created correctly and as expected? Usually character variables have a default length of 8 characters and your names are larger so it could be that. You need to add in a length statement for the source variable if that is the case. 

Also, it's usually returned as all uppercase I believe and you're using lower case data, SAS is case sensitive for character comparisons.

 


@JibJam221 wrote:

Hello all, im having issues with the INDSNAME column. It outputs as it should... however Im looking to make this column permanent so that I can rename the source names to more understandable terms. I tried using INDSNAME then using IF-THEN statements to rename the sources into a new column, however these sources get automatically removed once further querying the table..  is there any way for me to make INDSNAME a permanent column in the dataset?

 

data work.totaltable;
	set work.1222872-work.1222998 indsname=Dsnames;
	source=Dsnames;
	run;

data totaltable;
	set work.totaltable;
	if source='work.1222872' then SourceTransc='Transaction 2287';
......
run;

 

 

 

JibJam221
Obsidian | Level 7
hello! Thanks for letting me know, I didnt know that!

and the Source variable is working, its outputting the sources as i'd like to. Im just hoping to find a way for it to stay when I try to further query the table.
Reeza
Super User
It will stay unless you dropped it.


Trace your code to show where it's dropped. Look for Keep/Drop statements and verify that your SET/DATA references are correct.
JibJam221
Obsidian | Level 7
I dont necessarily drop it, however I do use the work.totaltable to create a more queried version called work.finaltable, and use this to only include the variable "SourceTransc" and not "source".. Could this be the cause?
Reeza
Super User
"use this to only include the variable "SourceTransc" and not "source""

Sounds like you do drop it, but not including it in a KEEP statement maybe. Show the code for further assistance.
JibJam221
Obsidian | Level 7
data work.totaltable;
	set work.1222872-work.1222998 indsname=Dsnames;
	source=Dsnames;
	run;

data work.totaltable2;
	set work.totaltable;
	if source='work.1222872' then SourceTransc='Transaction 2287';
......
run;

proc sql;
create table work.FinalTable AS
select 
SourceTransc,
	First_Name, 
	Last_Name,
....
from work.totaltable2;
run;
Reeza
Super User
If you don't explicitly keep it, (listing in SQL) then it's implicitly dropped. Add it to the SQL select statement if you want to keep it...
JibJam221
Obsidian | Level 7
I actually just tried to and it still isnt working. It shows the column names however the columns are empty
JibJam221
Obsidian | Level 7

Hello all,

im having issues with the INDSNAME column. It outputs as it should... however Im looking to make this column permanent so that I can rename the source names to more understandable terms. I tried using INDSNAME then using IF-THEN statements to rename the sources into a new column, however these sources get automatically removed once further querying the table.. 

is there any way for me to make INDSNAME a permanent column in the dataset?

Tom
Super User Tom
Super User

Your first step cannot work.

This statement is not valid SAS syntax.

set work.1222872-work.1222998 indsname=Dsnames;

1222872 and 1222998 are not valid member names for SAS datasets.

 

If you have set the VALIDMEMNAME option to EXTEND then perhaps you could use 

set work.'1222872'n-work.'1222998'n indsname=Dsnames;
JibJam221
Obsidian | Level 7
hello, I do have the ValidMemName option listed at the top of the program.
Is there a way to make the INDSNAME a permanent column?
Tom
Super User Tom
Super User

Setting the VALIDMEMNAME option to EXTEND only means that SAS will ALLOW the use of the non-standard names.

To actually reference the datasets that have such names you will still need to use a NAME LITERAL in your code instead of normal syntax.

124  options validmemname=extend;
125  data work.123;
          --------
          22
          201
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, /, ;, _DATA_, _LAST_, _NULL_.

ERROR 201-322: The option is not recognized and will be ignored.

126   x=2;
127  run;

You probably should add LENGTH statement(s) to make sure that the two variables you are using are long enough.

options validmemname=extend;
data work.'123'n '124'n;
 x=2;
run;

data want;
  length temporary permanent $70 ;
  set work.'123'n - work.'124'n indsname=temporary ;
  permanent=temporary;
run;

If the values are "disappearing" then add some diagnostic steps to see when they disappear.

 

Reeza
Super User

@JibJam221 wrote:
hello! Thanks for letting me know, I didnt know that!

and the Source variable is working, its outputting the sources as i'd like to. Im just hoping to find a way for it to stay when I try to further query the table.

I'm confused. You said the source variable is working. 

 

So is it working or not?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 13 replies
  • 1480 views
  • 2 likes
  • 3 in conversation